An integer is said to be a palindrome if it is equal to its reverse. For example, 79197…
- User
An integer is said to be a palindrome if it is equal to its reverse. For example, 79197 and 324423 are palindromes. In this task you will be given an integer N, 1 ≤ N ≤ 1000000. You must find the smallest integer M ≥ N such that M is a prime number and M is a palindrome.
For example, if N is 31 then the answer is 101. Input A single integer N, (1 ≤ N ≤ 1000000), on a single line.Output Your output must consist of a single integer, the smallest prime palindrome greater than or equal to N.
Example
Input: 31 Output: 101
Assistant
pythonn = int(input()) def is_palindrome(m): s = str(m) return s == s[::-1] def is_prime(m): if m <= 1: return False if m == 2: return True if m % 2 == 0: return False for i in range(3, int(m**0.5) + 1, 2): if m % i == 0: return False return True if n <= 2: print(2) else: start = n if n % 2 != 0 else n + 1 m = start while True: if is_palindrome(m): if m in (2, 5): if is_prime(m): print(m) break else: last_digit = m % 10 if last_digit in {1, 3, 7, 9}: if is_prime(m): print(m) break m += 2
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.