Maths vs Stats computations
If total time taken to calculate perfect numbers from 1 to 10000 is 12 seconds(on i5 2nd gen 12gb ram)
then find out total time taken for perfect numbers
from 1 to 20000?
sol:
24 seconds is wrong
Because as the number becoming large, computation
calculation increases there by delay in time
So time is 54 seconds(in my system)
#Find all perfect number 1 -100
import time as t
start=t.time()
z=1
while z<=20000:
n=z
i=1
sum=0
while i<n:
if n%i==0:
sum=sum+i
i=i+1
if sum==n:
print(n, end="\t")
z=z+1
end=t.time()
print("Total time #",end-start, " seconds")
Comments
Post a Comment