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.
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.
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check if a number is divisible by all prime divisors of another number
- Check if N is a Weak Prime number or not
- C Program to Check Whether a Number is Prime or not
- Check if a number is a Pythagorean Prime or not
- Check if a number is Quartan Prime or not
- Check whether the given number is Wagstaff prime or not
- Check if the first and last digit of number N is prime and their sum is less than K
- Check if a number is Full Prime
- Check if N is a Balanced Prime number or not
- Check whether N is a Dihedral Prime Number or not
- Check a number for Permutable Prime
- Check whether a number is Good prime or not
- Check if a number is Primorial Prime or not
- Check if the number is a Prime power number
- Python program to check whether a number is Prime or not
- Check if a number can be written as a sum of 'k' prime numbers
- Check if all Prime factors of number N are unique or not
- Check if A can be converted to B by reducing with a Prime number