In number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3 (excluding itself), and 1 + 2 + 3 = 6, so 6 is a perfect number.
Given a number, find out whether it’s a perfect number or not.
Sample Input:
28
Sample Output:
True
For the above sample, number 28 is perfect as 1 + 2 + 4 + 7 + 14 = 28. Number 1, 2, 4, 7 and 14 are 28’s divisors.
数据结构和算法:初级练习题# 9 – 完全数
完全数,又称完美数或完备数,是一些特殊的自然数。它所有的真因子(即除了自身以外的约数)的和(即因子函数),恰好等于它本身。如果一个数恰好等于它的真因子之和,则称该数为“完全数”。第一个完全数是6,第二个完全数是28,第三个完全数是496,后面的完全数还有8128、33550336等等。截至2018年,相关研究者已经找到51个完全数。
给定一个整数,确认它是否是完全数。
样例输入:
28
样例输出:
True
上面的样例输入中,数字28可以分解为 1 + 2 + 4 + 7 + 14 = 28。1、2、4、7、14都是28的真因子,所以28是完全数。