Emirp is the word “prime” spelled backwards, and it refers to a prime number that becomes a new prime number when you reverse its digits. Emirps do not include palindromic primes (like 151 or 787) nor 1-digit primes like 7. 107, 113, 149, and 157 – reverse them and you’ve got a new prime number on your hands. Source: Wiki
Given a number n, the task is to print all Emrips smaller than or equal to n.
Input : n = 40 Output : 13 31 Input : n = 100 Output : 13 31 17 71 37 73 79 97
Below are the steps :
1) Use Sieve of Eratosthenes to generate all primes smaller than or equal to n. We can also use sieve of sundaram.
2) Traverse all generated prime numbers. For every traversed prime number print this number and its reverse if following conditions are satisfied.
………….a) If reverse is also prime.
………….b) Reverse is not same as prime (palindromes are not allowed)
………….c) Reverse is smaller than or equal to n.
Below is the implementation of above idea.
13 31 17 71 37 73 79 97
This article is contributed by Shivam Pradhan ( anuj_charm). 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.
- Check if given number is Emirp Number or not
- Bitwise AND of the sum of prime numbers and the sum of composite numbers in an array
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Numbers less than N which are product of exactly two distinct prime numbers
- Count numbers which are divisible by all the numbers from 2 to 10
- Count numbers which can be constructed using two numbers
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Add two numbers using ++ and/or --
- Sum of first n even numbers
- LCM of N numbers modulo M
- Ludic Numbers