31 December 2024

How to check divisibility by 65521 without a remainder operation:

bool div65521(uint32_t n) {
  const uint64_t c = 1 + ~0ULL / 65521;
  return n * c < c;
}
< back to journal