mirror of
https://github.com/correl/euler.git
synced 2024-11-30 11:09:52 +00:00
executable code, yay
git-svn-id: file:///srv/svn/euler@50 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
This commit is contained in:
parent
4b1ce72158
commit
3373f8f1f7
1 changed files with 17 additions and 16 deletions
33
e021.py
33
e021.py
|
@ -1,9 +1,6 @@
|
||||||
from e007 import is_prime
|
from e007 import is_prime
|
||||||
from e012 import factor
|
from e012 import factor
|
||||||
|
|
||||||
MIN = 2
|
|
||||||
MAX = 10000
|
|
||||||
|
|
||||||
def proper_divisors(n):
|
def proper_divisors(n):
|
||||||
"""Returns the proper divisors of n
|
"""Returns the proper divisors of n
|
||||||
|
|
||||||
|
@ -13,16 +10,20 @@ def proper_divisors(n):
|
||||||
# Knock off the last factor, since it is equal to n
|
# Knock off the last factor, since it is equal to n
|
||||||
return divisors[:-1]
|
return divisors[:-1]
|
||||||
|
|
||||||
sums = {}
|
if __name__ == '__main__':
|
||||||
amicable = []
|
MIN = 2
|
||||||
i = MIN
|
MAX = 10000
|
||||||
while i < MAX:
|
|
||||||
if not is_prime(i):
|
sums = {}
|
||||||
s = sum(proper_divisors(i))
|
amicable = []
|
||||||
sums[i] = s
|
i = MIN
|
||||||
if s in sums and i == sums[s] and i != s:
|
while i < MAX:
|
||||||
print i, s, sums[s]
|
if not is_prime(i):
|
||||||
amicable.append(i)
|
s = sum(proper_divisors(i))
|
||||||
amicable.append(s)
|
sums[i] = s
|
||||||
i = i + 1
|
if s in sums and i == sums[s] and i != s:
|
||||||
print 'Sum of amicable numbers less than {0}: {1}'.format(MAX, sum(amicable))
|
print i, s, sums[s]
|
||||||
|
amicable.append(i)
|
||||||
|
amicable.append(s)
|
||||||
|
i = i + 1
|
||||||
|
print 'Sum of amicable numbers less than {0}: {1}'.format(MAX, sum(amicable))
|
Loading…
Reference in a new issue