A palindromic prime (sometimes called a palprime) is a prime number that is also a palindromic number.
Given a number n, print all palindromic primes smaller than or equal to n. For example, If n is 10, the output should be “2, 3, 5, 7′. And if n is 20, the output should be “2, 3, 5, 7, 11′.
Idea is to generate all prime numbers smaller than or equal to given number n and checking every prime number whether it is palindromic or not.
- To find if a given number is prime or not- sieve-of-eratosthenes method
- To check whether the given number is palindromic number or not: Recursive function for checking palindrome
Below is the implementation of above algorithm:
Palindromic primes smaller than or equal to 100 are : 2 3 5 7 11
This article is contributed by Rahul Agrawal .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Length of largest sub-array having primes strictly greater than non-primes
- Longest Palindromic Substring using Palindromic Tree | Set 3
- Circular primes less than n
- Count Primes in Ranges
- Product of all primes in the range from L to R
- Print all Proth primes up to N
- Print all multiplicative primes <= N
- Alternate Primes till N
- Print all safe primes below N
- Check whether given three numbers are adjacent primes
- Check if a number is sandwiched between primes
- Number of primes in a subarray (with updates)
- Count number of primes in an array
- Sum of all Primes in a given range using Sieve of Eratosthenes
- Program for Goldbach’s Conjecture (Two Primes with given Sum)
Improved By : nitin mittal