如果一个整数只能被1和自己整除,就称这个数是素数。
如果一个数正着反着都是一样,就称为这个数是回文数。例如:6, 66, 606, 6666
如果一个数字既是素数也是回文数,就称这个数是回文素数
牛牛现在给定一个区间[L, R],希望你能求出在这个区间内有多少个回文素数。
输入包括一行,一行中有两个整数(1 ≤ L ≤ R ≤ 1000)
输出一个整数,表示区间内回文素数个数。
100 150
2
low,high=map(int,input().split())
print(len(tuple(0 for i in \
(2,3,5,7,11,101,131,151,181,191,313,353,373,383,727,757,787,797,919,929) \
if low<=i<=high)))
low,high=map(int,input().split()) res=0 for i in range(low,high+1): if str(i)[0]!=str(i)[-1] or i==1: continue t=True for j in range(2,i): if i%j==0: t=False break if t: res+=1 print (res)
def eladuosai(n): l = list(range(1, n+1)) l[0] = 0 for i in range(2, n+1): if l[i-1] != 0 : for j in range(i*2, n+1, i): l[j-1] = 0 result = [x for x in l if x != 0] return result L, R = map(int, input().split()) num = 0 prim = eladuosai(R) for i in range(len(prim)): if prim[i] >= L and str(prim[i]) == str(prim[i])[::-1]: num += 1 print(num)
import math
# 判断n是否为回文数且为素数
def is_prime_and_palindrome(n):
if str(n) != str(n)[::-1]:
return False
if n <= 1:
return False
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
start, end = map(int, input().split())
print(len(list(filter(lambda c: is_prime_and_palindrome(c), range(start, end + 1)))))
sushu_list = [] # inp = [int(x) for x in input().split()] # L = inp[0] # R = inp[1] L, R = [int(x) for x in input().split()] for i in range(L,R+1): sym = 0 for j in range(2,int(i**0.5)+1): if i%j == 0 : sym = 1 break if sym == 0: sushu_list.append(i) if 1 in sushu_list: sushu_list.pop(0) sum = 0 sushu_list = [str(x) for x in sushu_list] for x in sushu_list: if x == x[::-1]: sum += 1 print(sum)
# coding=utf-8 # 判断一个数是否为素数 def Prime_number(n): if n%2 == 0 : return False else: for i in range(3,n,2): if n%i == 0: return False return True # 判断一个数是否为回文数 def Palindrome(n): if str(n) == str(n)[::-1]: return True else: return False def fun(): s = map(int,raw_input().split()) L,R = s[0],s[1] count = 0 for i in range(L,R+1): if Prime_number(i) and Palindrome(i): count += 1 return count if __name__=='__main__': print(fun())