Given a number N, task is to Check whether it is a permutable prime number or not.
A Permutable prime number is that number which after switching the position of digits through any permutation is also prime. Some of the permutable prime numbers are 2, 3, 5, 7, 11, etc.
Input : 31 Output : Yes Explanation : Both 13 and 31 are prime. Input : 19 Output : No Explanation : 19 is prime but 91 is not
1) Construct Sieve of Eratosthenes to find the prime numbers efficiently.
2) Either generate every permutation of the number by switching its digits or use inbuilt C++ function next_permutation to check whether it is prime
3) If any permutation of digits is not prime, simply answer is NO, otherwise YES.
Below is the implementation of above approach.
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.
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Quick ways to check for Prime and find next Prime in Java
- Check whether the sum of prime elements of the array is prime or not
- Find coordinates of a prime number in a Prime Spiral
- Print the nearest prime number formed by adding prime numbers to N
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Check if the number is a Prime power number
- Prime numbers after prime P with sum S
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Print prime numbers with prime sum of digits in an array
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Sum of prime numbers without odd prime digits
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Permutation of first N positive integers such that prime numbers are at prime indices
- Permutation of first N positive integers such that prime numbers are at prime indices | Set 2
- Count all prime numbers in a given range whose sum of digits is also prime
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Check if a number can be written as a sum of 'k' prime numbers
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar