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.

  1. Initialize sum at 0.
  2. Loop through all numbers from 1 up to (but not including) target.
  3. If a number divides target perfectly, add it to sum.
  4. After the loop, print "true" if sum equals target, otherwise print "false".

01EXAMPLE 1

Inputtarget = 6
Outputtrue

Explanation: 1 + 2 + 3 = 6

02EXAMPLE 2

Inputtarget = 10
Outputfalse

Explanation: 1 + 2 + 5 = 8

Constraints

  • Use a standard loop.
  • Do not include the target number in the sum.
MathLoops
JavaScript
Loading...
3 Hidden

Input Arguments

target6

Expected Output

true

Click RUN to test your solution