Files
contests/21/main.py

47 lines
944 B
Python

import os
import math
import numpy as np
# Evaluate the sum all amicable numbers under 10000
# A pair of number is amicable if the sum of their proper divisors is equal
# to each other, they are then both called amicable numbers
def getDivs(n):
ds = [True] * math.ceil(n/2)
for i in range(1, len(ds)):
if ds[i] and n % (i+1) != 0:
j = i
while j < len(ds):
ds[j] = False
j = j + i + 1
res = []
for i in range(0, len(ds)):
if ds[i]:
res.append(i+1)
return res
def getSumDivs(n):
return sum(getDivs(n))
def main():
print("Hello, this is Patrick")
dsums = [getSumDivs(x) for x in range(1, 10001)]
res = 0
for i in range(len(dsums)):
di = dsums[i]
if (i+1) != di:
if di-1 < len(dsums):
if i+1 == dsums[di-1]:
res = res + i + 1
else:
dj = getSumDivs(di)
if i+1 == dj:
res = res + i + 1
print(res)
if __name__ == "__main__":
main()