-
Notifications
You must be signed in to change notification settings - Fork 0
/
p69.py
45 lines (37 loc) · 779 Bytes
/
p69.py
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
40
41
42
43
44
45
import math
import time
# def phi(n):
# output = n
# for i in range(2, n+1):
# counter = 0
# while (n % i == 0):
# n = n/i
# counter = counter + 1
# if counter > 0:
# output = output * (1 - float(1.0/i))
# return output
def phi(n):
result = n
i = 2
while i * i <= n:
if n % i == 0:
while n % i == 0:
n //= i
result -= result // i
i += 1
if n > 1:
result -= result // n
return result
max_val = 0
max_n = 1
for n in range(2, 1000001):
#start = time.time()
if float(float(n)/float(phi(n))) > max_val:
max_val = float(float(n)/float(phi(n)))
max_n = n
print max_val, max_n
#end = time.time()
#print n, end-start
if n % 10000 == 0:
print n
print max_val, max_n