AlgoScope

Primality Test

AlgorithmbeginnerNumber Theory

Try each divisor up to the square root. No hit means prime.

Decision · step 2 of 10Number Theory Basics: Is 97 prime?
2031425364758697i

97 mod 2 = 1, not zero. 2 is not a factor.

Open in the player →or start at step 2

What you will see

Candidate divisors walk up to sqrt(n); a hit marks composite.

How number theory basics works →

Cost

BestO(1)
AverageO(sqrt(n))
WorstO(sqrt(n))
SpaceO(1)

How you work with it here

play it through, step one change at a time, run it on your own input.

Screen readers: Numbers announce their value and role; each step announces the arithmetic performed.

Reduced motion: Values crossfade; no travelling digits.

Variants

  • Trial Division Deterministic
  • Miller-Rabin Probabilistic

Leads to

Topics that need this one first.

Taught by the same lesson

Number Theory Basics covers these too, in the same run.