The Perfect Number
MediumAcc. 91.2%
+25 XP 10
Mathematical Perfection
A Perfect Number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. Example: $6$ (divisors 1, 2, 3 $ o 1+2+3 = 6$).
The Assignment
Your function receives a parameter named target.
- Initialize
sumat 0. - Loop through all numbers from 1 up to (but not including)
target. - If a number divides
targetperfectly, add it tosum. - After the loop, print "true" if
sumequalstarget, otherwise print "false".
01EXAMPLE 1
Input
target = 6Output
trueExplanation: 1 + 2 + 3 = 6
02EXAMPLE 2
Input
target = 10Output
falseExplanation: 1 + 2 + 5 = 8
Constraints
- Use a standard loop.
- Do not include the target number in the sum.
MathLoops
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
target6
Expected Output
true
Click RUN to test your solution