The Circular Prime
HardAcc. 80.4%
+40 XP 20
The Infinite Loop of Primes
A Circular Prime is a prime number where every possible cyclic rotation of its digits is also a prime number. Example: 197. Rotations: 197, 971, 719. (All are prime!).
The Assignment
Your function receives a parameter num.
- Verify if
numis prime. - Calculate every possible rotation of its digits using math.
- Example rotation of 123: $(123 imes 10 + 1) dots$ or using length-based math.
- Check if every rotation is also a prime.
- Print "true" if all are prime, otherwise "false".
01EXAMPLE 1
Input
num = 197Output
trueExplanation: All rotations (197, 971, 719) are prime.
Constraints
- Perform rotations without strings.
- Use nested loops to check all variants.
MathLoops
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
num197
Expected Output
true
Click RUN to test your solution