AKS Primality Test

Theoretical Basis

The AKS algorithm is based on the theorem: An integer $n \ge 2$ is prime if and only if the following congruence holds for all $a$ coprime to $n$:

$$(x - a)^n \equiv (x^n - a) \pmod{x^r - 1, n}$$

Note: AKS is a deterministic algorithm but has high computational complexity for polynomials. For very large numbers, the process can take significant time.

⚠️ Precision Limit: This demo uses standard JS numbers. For $n > 10^7$, integer overflow may occur, causing incorrect results. For real-world use, a BigInt implementation is needed.