Prime Palindromes
Time limit1sMemory limit256 MB
List all palindromic prime numbers between a and b (up to 100 million) in increasing order, ending output with -1.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Brute force
- Solved
- No attempts yet
Problem
151 is a prime palindrome because it is prime and reads the same from left to right and from right to left. A palindrome is a number whose digits are unchanged when read in reverse. The number 1234 becomes 4321 when read backward, so it is not a palindrome.
Given two integers a and b, find every prime palindrome from a through b, inclusive.
Input
The first line contains two natural numbers a and b separated by a space.
The limits are 5 ≤ a < b ≤ 100,000,000.
Output
Print the prime palindromes from a through b in increasing order, one per line.
After printing all such numbers, print -1 on the final line.