题解 | #完全数计算#
完全数计算
http://www.nowcoder.com/questionTerminal/7299c12e6abb437c87ad3e712383ff84
import math
def getyinshuhe(num): #得到一个数的因数和
nums=set()
for i in range(1,int(math.sqrt(num))+1):
if num % i ==0:
nums.add(i)
nums.add(num//i)
if num in nums:
nums.remove(num)
return sum(nums)
count=0
n=int(input())
for i in range(1,n+1):
if i==getyinshuhe(i): #判断是否为完全数
# print(i)
count+=1
print(count)
def getyinshuhe(num): #得到一个数的因数和
nums=set()
for i in range(1,int(math.sqrt(num))+1):
if num % i ==0:
nums.add(i)
nums.add(num//i)
if num in nums:
nums.remove(num)
return sum(nums)
count=0
n=int(input())
for i in range(1,n+1):
if i==getyinshuhe(i): #判断是否为完全数
# print(i)
count+=1
print(count)