We are given a number n. Our task is to check whether the number is circular prime or not.
Circular Prime : A prime number is said to be a circular prime if after any cyclic permutations of the digits, it remains a prime.
Input : n = 113 Output : Yes All cyclic permutations of 113 (311 and 131) are prime. Input : 1193 Output : Yes
The idea is simple, we generate all permutations of given number and check each permutation for prime. To generate permutations, we one by one move last digit to first position.
Clearly numbers containing 0, 2, 4, 5, 6, or 8 can never be circular primes as numbers ending with these will always be divisible by 2 or 5. Hence one of their permutation will not be a prime. While counting digits in first step, we can also check if current digit is one of these.
This article is contributed by Vineet Joshi. 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.
- Check whether the sum of prime elements of the array is prime or not
- C Program to Check Whether a Number is Prime or not
- Python program to check whether a number is Prime or not
- Check whether the given number is Wagstaff prime or not
- Check whether N is a Dihedral Prime Number or not
- Check whether a number is Good prime or not
- Check whether the sum of absolute difference of adjacent digits is Prime or not
- Check whether the given numbers are Cousin prime or not
- Check whether count of distinct characters in a string is Prime or not
- Check whether the frequencies of all the characters in a string are prime or not
- Check whether the given number is Euclid Number or not
- Check whether given number N is a Moran Number or not
- Check whether a number has exactly three distinct factors or not
- Check whether a number is semiprime or not
- Check whether a number is Emirpimes or not
- 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
- Check if a number is a Pythagorean Prime or not
- Check if a number is Quartan Prime or not
- Check if a number is Primorial Prime or not