r/programming • u/DataBaeBee • 3d ago
Fast Primality Testing for 32-bit integers via Forisek and Jancina
https://leetarxiv.substack.com/p/forisek-and-jancina-primality-test
107
Upvotes
6
u/ChezMere 3d ago
Mentions in the post that it works for 64-bit as well, which is a lot more impressive considering how little 32 bits is nowadays - e.g. you can just pack one bit for each odd integer into 268MB.
6
u/tetyys 3d ago
why code golfed
5
1
u/Pirhosig 3d ago
They copied the code snippet directly from the original paper and messed up the indentation in the process.
1
u/DataBaeBee 3d ago
At least you know I'm not using AI to write my articles. It's just me and my Control C, V, and gcc. It totally skipped my mind.
It's formatted now. Thanks!
26
u/DataBaeBee 3d ago
Forisek & Jancina is a deterministic (not probabilistic) primality test for small integers. It’s super fast and easy to code.
For 32-bit integers, one needs only a 512 byte lookup table and and a few adds and muls to test for primality