Created
July 22, 2012 09:04
-
-
Save iizukak/3158974 to your computer and use it in GitHub Desktop.
Project Euler Problem 21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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