Skip to content

Instantly share code, notes, and snippets.

@iizukak
Created July 22, 2012 09:04
Show Gist options
  • Select an option

  • Save iizukak/3158974 to your computer and use it in GitHub Desktop.

Select an option

Save iizukak/3158974 to your computer and use it in GitHub Desktop.
Project Euler Problem 21
#project euler problem 21
#http://projecteuler.net/problem=21
#auther @iizukak
#10000以下の友愛数の和を求める
def finddiv(n):
ans = [0]
for i in range(1, n+1):
tmp = 0
for j in range(1, (i / 2) + 1):
if i % j == 0:
tmp += j
ans.append(tmp)
return ans
def findfriend(n):
ans = 0
a = finddiv(n)
for i in range(1, len(a)):
if a[i] < len(a) and a[i] != i and a[a[i]] == i:
ans += i
ans += a[i]
a[i] = 0 #重複削除
return ans
print(findfriend(10000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment