Birthday paradox

After O(√p) steps of random walk mod p, collision expected. gcd of collision difference with n gives p.

Advertisement

Floyd's cycle detection

Tortoise + hare: x_i and x_{2i}. When they collide mod p → gcd yields p.

Advertisement

Brent's improvement

Fewer gcd computations. About 25% faster in practice.