Skip to content

Add solution 64 #3744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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