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.

  1. Verify if num is prime.
  2. Calculate every possible rotation of its digits using math.
    • Example rotation of 123: $(123 imes 10 + 1) dots$ or using length-based math.
  3. Check if every rotation is also a prime.
  4. Print "true" if all are prime, otherwise "false".

01EXAMPLE 1

Inputnum = 197
Outputtrue

Explanation: All rotations (197, 971, 719) are prime.

Constraints

  • Perform rotations without strings.
  • Use nested loops to check all variants.
MathLoops
JavaScript
Loading...
3 Hidden

Input Arguments

num197

Expected Output

true

Click RUN to test your solution