Given an integer N, the task is to print all the multiplicative primes ≤ N.
Multiplicative Primes are the primes such that the product of their digits is also a prime. For example; 2, 3, 7, 13, 17, …
Input: N = 10
Output: 2 3 5 7
Input: N = 3
Output: 2 3
Approach: Using Sieve of Eratosthenes check for all the primes ≤ N whether they are multiplicative primes i.e. product of their digits is also a prime. If yes then print those multiplicative primes.
Below is the implementation of the above approach:
2 3 5 7
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Print all safe primes below N
- Print all Proth primes up to N
- Sieve of Sundaram to print all primes smaller than n
- Segmented Sieve (Print Primes in a Range)
- 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
- Multiplicative order
- Modular multiplicative inverse from 1 to n
- Modular multiplicative inverse
- Non-repeating Primes
- Circular primes less than n
- Palindromic Primes
- Tetradic Primes
- Woodall Primes
- Alternate Primes till N
- Count Primes in Ranges
- Product of all primes in the range from L to R
- Maximum Primes whose sum is equal to given N
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.