-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
32 lines (27 loc) · 872 Bytes
/
Copy pathgpt4_solution.py
File metadata and controls
32 lines (27 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import json
import time
# START - CODE GENERATED BY gpt4
def solution():
def continued_fraction_period(n):
m, d, a0 = 0, 1, int(n**0.5)
if a0 * a0 == n:
return 0 # Perfect square, no period
a = a0
period = 0
while a != 2 * a0:
m = d * a - m
d = (n - m * m) // d
a = (a0 + m) // d
period += 1
return period
count_odd_periods = 0
for n in range(2, 10001):
if continued_fraction_period(n) % 2 == 1:
count_odd_periods += 1
return count_odd_periods
# END - CODE GENERATED BY gpt4
cpu_s, wall_s = time.process_time(), time.time()
result = solution()
cpu_e, wall_e = time.process_time(), time.time()
cpu_time, wall_time = cpu_e - cpu_s, wall_e - wall_s
print(json.dumps({"solution": result, "cpu": cpu_time, "wall": wall_time}))