Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions project_euler/problem_064/sol64.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#import time
import time

# square root function
from math import sqrt

# time at the start of program execution
start = time.time()

# function to calculate the continued fraction
def cf(n):
mn = 0.0
dn = 1.0
a0 = int(sqrt(n))
an = int(sqrt(n))
period = 0
if a0 != sqrt(n):
while an != 2*a0:
mn = dn*an - mn
dn = (n - mn**2)/dn
an = int((a0 + mn)/dn)
period += 1
return period

# counter
counter = 0

# for loop from 0 to 10000
for i in xrange(10000):
if cf(i) % 2 != 0:
counter += 1

# number of instances
print counter

# time at the end of program execution
end = time.time()

# total time taken to run the program
print end - start