-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt3_solution.py
More file actions
39 lines (34 loc) · 982 Bytes
/
Copy pathgpt3_solution.py
File metadata and controls
39 lines (34 loc) · 982 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
33
34
35
36
37
38
39
import json
import time
# START - CODE GENERATED BY gpt3
def is_permutation(num1, num2):
return sorted(str(num1)) == sorted(str(num2))
def euler_totient(n):
result = n
p = 2
while p * p <= n:
if n % p == 0:
while n % p == 0:
n //= p
result -= result // p
p += 1
if n > 1:
result -= result // n
return result
def solution():
min_ratio = float('inf')
result = 0
for n in range(2, 10**7):
phi_n = euler_totient(n)
if is_permutation(n, phi_n):
ratio = n / phi_n
if ratio < min_ratio:
min_ratio = ratio
result = n
return result
# END - CODE GENERATED BY gpt3
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}))