Untitled
unknown
python
2 years ago
687 B
11
Indexable
import math
def isPal(n, temp):
# If num is negative, make it positive
# base case
if (n == 0):
return temp;
# stores the reverse of a number
temp = (temp * 10) + (n % 10);
return isPal(n // 10, temp);
def main(srt, n):
prime = [True for i in range(n + 2 )]
prime[0] = False
prime[1] = False
ans = 0
for p in range(2, int(math.sqrt(n))+1):
if prime[p] == True:
for i in range(p*p, n+1, p):
prime[i] = False
# Print all prime numbers
for p in range(srt, n+1):
if prime[p] and isPal(p, 0)==p:
ans += 1
return ans
print(main(150, 200))Editor is loading...
Leave a Comment