题解 | #完全数计算#
完全数计算
http://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84
n = int(input()) counnnnnnnnnnnnnnnnnnnnnnnnnt = 0 def wanmei(a): couuuuuunt = 0 shu = a yinshu = 2 true_yinshu = 1#多个相同的因数时的实际因数 max_yinshu = a ** 0.5 while (shu > 1 and yinshu <= max_yinshu): if (shu % yinshu == 0): shu = shu / yinshu # print(yinshu) true_yinshu *= yinshu couuuuuunt = couuuuuunt+true_yinshu+(a/true_yinshu) else: yinshu += 1 true_yinshu = 1 return couuuuuunt for i in range(2, n + 1): if (wanmei(i)+1 == i): counnnnnnnnnnnnnnnnnnnnnnnnnt += 1 # print(i) print(counnnnnnnnnnnnnnnnnnnnnnnnnt)