Miller-Rabin Test
A probabilistic primality test that:
- Writes n-1 as d×2s
- Chooses random witnesses (5 in our case)
- For each witness a:
- Computes x = ad mod n
- If x ≡ 1 or x ≡ -1 → continue
- Squares x up to s-1 times looking for -1
- If any witness shows compositeness → composite
- If all witnesses pass → probably prime
Fast for large numbers with 97.5% accuracy (5 iterations)