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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Length of largest sub-array having primes strictly greater than non-primes
- Count primes that can be expressed as sum of two consecutive primes and 1
- Count of primes below N which can be expressed as the sum of two primes
- Nth Term of a Fibonacci Series of Primes formed by concatenating pairs of Primes in a given range
- Longest Palindromic Substring using Palindromic Tree | Set 3
- Make palindromic string non-palindromic by rearranging its letters
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Segmented Sieve (Print Primes in a Range)
- Sieve of Sundaram to print all primes smaller than n
- Remove duplicates from an array of small primes
- Find the prime numbers which can written as sum of most consecutive primes
- Circular primes less than n
- Program for Goldbach’s Conjecture (Two Primes with given Sum)
- Prime points (Points that split a number into two primes)
- Count Primes in Ranges
- K-Primes (Numbers with k prime factors) in a range
- Check whether given three numbers are adjacent primes
- Check if a number is sandwiched between primes
- A Kobayashi Maru Approach to Finding Primes
- Number of primes in a subarray (with updates)