-
Notifications
You must be signed in to change notification settings - Fork 0
/
Truncatable_primes.py
49 lines (48 loc) · 1.48 KB
/
Truncatable_primes.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
46
47
48
49
input = int(input("Enter your input: "))
mainlist = []
sum = 0
for x in range(1, input):
k = 11
for user in range(10, x):
user = str(user)
# user = input("Enter the number: ")
y = user
maincounter = 11
while len(user)!=0:
count = 0
for i in range(2, int(user)):
if int(user)%i == 0:
count+=1
if count > 0:
break
else:
maincounter +=1
if count>0 or user == "1":
# print ("not truncatable from left to right")
break
if count == 0:
user = user[1:]
if len(user) == 0:
user = y
while len(user)!=0:
counter = 0
for i in range(2, int(user)):
if int(user)%i == 0:
counter+=1
if counter > 0:
break
else:
maincounter +=1
if counter>0 or user == "1":
# print ("not truncatable from right to left")
break
if counter == 0:
user = user[:-1]
else:
# print (y, "is perfect truncatable prime from both ends:)", maincounter)
if y not in mainlist:
mainlist.append(y)
for z in mainlist:
sum+=int(z)
print (z)
print ("sum", sum)