summaryrefslogtreecommitdiff
path: root/Problem21.py
blob: 42632be437d2be4fc19c4fcb2567fed810e6409f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def amicablesum(n):
    sum = 0
    sum2 = 0
    for x in range(1,int(n/2)+1):
        if n%x==0:
            sum+=x
    for x in range(1, int(sum/2)+1):
        if sum%x==0:
            sum2 +=x
    if (n!=sum)and(sum2 == n): return n
    else: return 0
sumcounter = 0
for x in range(1,10000):
    sumcounter += amicablesum(x)
    print(sumcounter)
print("final sum of amicable numbers is:" ,sumcounter)