Project Euler

Solution Project Euler – Problem 21: Amicable Numbers

# Sum of amicable number

def divisor_sum(x):
# x=raw_input('Enter the number?: ')
y=int(x)
sum=0
for i in range(1,y):
if(y%i == 0):
sum+=i
return sum

import time
sum1=0
start = time.time()
for t in range(1,10000):
call = divisor_sum(t)
call1= divisor_sum(call)
if call1 == t:
sum1 = sum1+int(call1)
elapsed = time.time() - start
print("%s found in %s seconds") % (sum1,elapsed)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s