Skip to content

Instantly share code, notes, and snippets.

@adamcheasley
Created January 18, 2018 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcheasley/101441a0b3bcd3c5bae50f7e88ccd331 to your computer and use it in GitHub Desktop.
Save adamcheasley/101441a0b3bcd3c5bae50f7e88ccd331 to your computer and use it in GitHub Desktop.
import requests
def sum_of_proper_divisors(n):
divisor_sum = 1
for x in range(2, int((n / 2) + 1)):
if n % x == 0:
divisor_sum += x
return divisor_sum
n = 4259751
while True:
sum_of_n_divisors = sum_of_proper_divisors(n)
if sum_of_proper_divisors(
sum_of_n_divisors) == n and n < sum_of_n_divisors:
try:
requests.post(
'https://safe-eyrie-79589.herokuapp.com/',
data={'key':'sqo3rZsduoeT4GGbMVbWuVpscp', 'lower': n, 'higher': sum_of_n_divisors},
)
except:
print("error posting data")
print("found amicable pair {}, {}".format(n, sum_of_n_divisors))
n += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment