Skip to content

Conversation

@Colton1skees
Copy link
Contributor

@Colton1skees Colton1skees commented Dec 28, 2025

Implements a fast linear congruence solver mod 2^n, exploiting a bunch of ways to make things faster when the modulus is a power of two.

  • a % MOD == a & (MOD - 1)
  • gcd(a, MOD) == 1 << tzcnt(a)
  • Extended euclidean algorithm only needs to compute gcd(a, MOD) and a*x == gcd(a, MOD), since MOD*y simplifies to zero. The latter is solved using the fast modular multiplicative inverse algorithm
  • Some other similar bithacks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants