An integer is a perfect number if the sum of its factors that are less than itself is equal to itself.
For example:
6 is a perfect number. This is because the factors of 6 that are less than 6 are 1, 2 and 3 and 1+2+3=6.
8 is NOT a perfect number because the factors of 8 that are less than 8 are 1,2,and 4 and 1+2+4 is NOT equal to 8.
28 is a perfect number because the factors of 28 that are less than 28 are 1,2,4,7,and 14 and 1+2+4+7+14 is equal to 28.
1. Read the integer n.
2. Get the sum of the factors of n that are less than n
3. If the sum of factors less than n is equal to n then n is a perfect number
No comments:
Post a Comment