题目大概是一个素数的翻转数也是一个素数
eg:37是第12个素数
37的翻转数是73
73是第21一个素数
|12-3*7|<=T(门限)and |12-21|<=T(门限)
求[n1,n2]这个区间内有多少个符合条件的素数
'''
Author: 365JHWZGo
Description: 考试题
Date: 2021-09-20 15:13:24
FilePath: \Python\demo2.py
LastEditTime: 2021-09-20 15:49:52
LastEditors: 365JHWZGo
'''
def judgePrime(x):
if x == 2:
return True
elif x % 2 == 0:
return False
for i in range(3, int(x**0.5) + 1, 2):
if x % i == 0:
return False
return True
n1, n2, T = map(int, input().split())
prime = dict()
ans = []
j = 0
for i in range(2, n2 + 1):
if judgePrime(i):
j += 1
prime[i] = j
#print(prime)
for i in range(n1, n2 + 1):
if i in prime.keys():
s = list(str(i))
s.reverse()
t = eval('*'.join(s))
reverseInt = int(''.join(s))
if reverseInt in prime.keys():
indexOri = prime[i]
indexRev = prime[reverseInt]
if (-T <= indexOri - t <= T) and (-T <= indexOri - indexRev <= T):
ans.append(i)
ans.sort()
for i in range(len(ans)):
if i != len(ans) - 1:
print(ans[i])
else:
print(ans[i], end='')