This is my first challenge!
Perfect number is a positive integer, that is equal to the sum of all its divisors, except itself.
6 is perfect number, since
1 + 2 + 3 = 6.
On the other hand
12 is not, because
1 + 2 + 3 + 4 + 6 = 16 != 12.
Your task is simple, write a program, which will, for given
n, print one of these messages:
I am a perfect number, because
d1 + d2 + ... + dm = s == n
I am not a perfect number, because
d1 + d2 + ... + dm = s [<>] n
d1, ... dm are all divisors of
n except for
s is the sum of all divisors
d1, ..., dm (again, without
[<>] is either
s < n) or
s > n).
6: "I am a perfect number, because 1 + 2 + 3 = 6 == 6"
12: "I am not a perfect number, because 1 + 2 + 3 + 4 + 6 = 16 > 12"
13: "I am not a perfect number, because 1 = 1 < 13"
nis not bigger than your language's standard
- You can read
nfrom standard input, from command line arguments or from a file.
- Output message has to be printed on standard output and no additional characters can appear in the output (it may have trailing whitespace or newline)
- You may not use any built-ins or library functions which would solve the task (or its main part) for you. No
GetDivisors()or something like that.
- All other standard loopholes apply.
This is code-golf so shortest code in bytes wins!
==in the same equation? That makes no sense. It should be
d1 + d2 + ... + dm = s = nIMO. \$\endgroup\$