-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject_Euler_26.py
More file actions
51 lines (41 loc) · 845 Bytes
/
Project_Euler_26.py
File metadata and controls
51 lines (41 loc) · 845 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
40
41
42
43
44
45
46
47
48
49
50
51
n=10000
list=[]
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * 2, n+1, p):
prime[i] = False
p += 1
for p in range(2, n+1):
if prime[p]:
list.append(p)
#print(list)
def cycle(n):
c=0
r=(1%n)*10
if r==0:
return 0
while True:
r=(r%n)*10
c=c+1
if r==0:
return 0
if r==10:
break
return c
final=[]
T=int(input())
for i in range(T):
n=int(input())
max=0
for p in list:
if p<n:
if max<cycle(p):
max=cycle(p)
f=p
else:
final.append(f)
break
for i in range(T):
print(final[i])