The next task in this track (the Residue ring) needs to know whether a number is prime while the program is still compiling — to forbid division for composite moduli. A normal runtime function will not do: the answer has to exist before the program runs. C++ has a keyword for functions like this.
Implement isPrime(n) so the compiler can evaluate it at compile time. The tests call it inside static_assert — if your function cannot run during compilation, the build fails.
isPrime must be usable in static_assert (compile-time evaluation)constexpr on a function actually promise the compiler?If n = ab and a <= b, then aa <= n. So one divisor in [2, sqrt(n)] is enough to prove n composite.
Avoid floating-point sqrt in constexpr code — the loop condition d * d <= n does the same job in integers.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.