-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask35.py
More file actions
85 lines (73 loc) · 2.18 KB
/
Copy pathtask35.py
File metadata and controls
85 lines (73 loc) · 2.18 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Число 197 называется круговым простым числом, потому что все перестановки его цифр с конца в начало являются простыми числами: 197, 719 и 971.
Существует тринадцать таких простых чисел меньше 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79 и 97.
Сколько существует круговых простых чисел меньше миллиона?
"""
import check_simple
from factorial import factorial
res =[]
def changer(n,sshelve,a=[]):
if n != []:
for i in n:
n2 = n[:]
n2.remove(i)
sshelve1 = sshelve
sshelve1 += str(i)
changer(n2,sshelve1,a=a)
#print(1)
else:
a.append(sshelve)
def changer_number(n):
#global res
list = [int(i) for i in str(n)]
res1 = []
changer(list,'',a = res1)
res1 = [int(i) for i in res1]
for i in res1:
res_a = res1[:]
res_a.remove(i)
if i in res_a:
res1 = res_a
return res1
a_a = check_simple.simple_a(10**6)
#a_a = [2,3,5,7,11,13,17,31,37,71,73,79,97]
count = 0
list_anon = []
"""for i in range(3,10**5,2):#first version
k = len(changer_number(i))
for number in changer_number(i):
if i in list_anon:
c = 0
break
else:
if number in a_a:
c = 1
continue
else:
c = 0
break
if c:
count+=factorial(k)
for number in changer_number(i):
list_anon.append(number)
"""
def _count(list):#second version(the best)
global count
for a in a_a:
list_variant = changer_number(a)
for lis in list_variant:
if lis in a_a:
c = 1
continue
else:
c = 0
break
if c == 1:
for i in list_variant:
a_a.remove(i)
count+=factorial(len(list_variant))
_count(a_a)
if __name__ == '__main__':
#_count(a_a)
#print(count)
print((changer_number(1234)))