An integer is said to be a palindrome if it is equal to its reverse in a string form. For example, 79197 and 324423 are palindromes. In this task you will be given an integer N. You must find the smallest integerM >= N such that M is a prime number and also apalindrome.
Input: N. An integer.
Output: A prime palindrome. An integer.
Example:
1
2
3
|
checkio( 31 ) = = 101
checkio( 130 ) = = 131
checkio( 131 ) = = 131
|
How it is used: Prime numbers are very useful for many IT sectors (cryptography, mathematical software).
__author__ = 'Administrator'
import math
def isPalindrome(item):
s=str(item)
rs=''
for c in reversed(s):
rs+=c
if s==rs:
return True
else:
return False
def isPrime(item):
if item==1:
return False
i=2
m=math.sqrt(item)
while i<=m:
if item%i==0:
return False
i+=1
return True
def isPalindrom2(n):
"""
Check integer for palindrom
>>> isPalindrom(131)
True
>>> isPalindrom(130)
False
"""
return str(n) == str(n)[::-1]
def checkio(item):
while True:
if isPalindrome(item) and isPrime(item):
return item
else:
item+=1
print(checkio(2))