๐Ÿš€ Wow, solving #primality with deterministic flair, while the rest of us plebs just use "is it divisible by 2?" ๐Ÿค”โœจ Enjoy this riveting saga of counting zeroes and modular math, because nothing screams #excitement like an inline function and a C code snippet! ๐Ÿ™ƒ๐Ÿ”ข
https://www.jeremykun.com/2026/04/07/deterministic-miller-rabin/ #modularmath #coding #Cprogramming #inlinefunctions #HackerNews #ngated
Deterministic Primality Testing for Limited Bit Width

Problem: Determine if a 32-bit number is prime (deterministically) Solution: (in C++) // Bases to test. Using the first 4 prime bases makes the test deterministic // for all 32-bit integers. See https://oeis.org/A014233. int64_t bases[] = {2, 3, 5, 7}; inline int countTrailingZeros(uint64_t n) { if (n == 0) return 64; return __builtin_ctzll(n); } int64_t modularExponentiation(int64_t base, int64_t exponent, int64_t modulus) { int64_t res = 1; int64_t b = base % modulus; int64_t e = exponent; while (e > 0) { if (e & 1) { // Doesn't overflow because we assume 32-bit integer inputs res = (res * b) % modulus; } b = (b * b) % modulus; e >>= 1; } return res; } bool isPrime(int64_t n) { if (n < 2) return false; if (n < 4) return true; if (!

Math โˆฉ Programming

Did you know?

"An Elliptic Curve Primality Proving (ECPP) algorithm was used via a primality proving program, Primo 4.3.0 - LX64, to generate a primality certificate which deterministically verifies the primality of p. The certification process took 39 days and 8 hours to complete using an AMD Ryzen Threadripper 2950X (16-Core, 32-Thread, 3.5GHz Base)."

http://www.primepairs.com/primo-B3F56036B033B.out

#didyouknow #ellipticcurve #primality #mathematics

From the 70's, Shanks' SQUFOF algorithm for prime factorising using square forms, with a mention of the HP-65...

"""
...to prove this I had only a hand-held HP-65 with its very small memory (100 steps in the program). Obviously, one cannot put the huge BRIMOR on such a machine. But one can put on the simple algorithm...
... factor the 19-digit Nโ‚€ as
(22) Nโ‚€ = 139001459 ยท 8294312261
even though the HP-65 only computes with 10-digit numbers.
"""

https://homes.cerias.purdue.edu/~ssw/shanks.pdf

#hpcalc #hp65
#primality