Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modular arithmetic for Mersenne numbers #6

Open
make-github-pseudonymous-again opened this issue May 28, 2020 · 1 comment
Open

Modular arithmetic for Mersenne numbers #6

make-github-pseudonymous-again opened this issue May 28, 2020 · 1 comment

Comments

@make-github-pseudonymous-again
Copy link
Member

Let r be the radix of representation, then computing x % r^k-1 can be reduced using the following identity (with R = r^k):

x = x % R + x // R (mod R-1)

See https://en.wikipedia.org/wiki/Lucas%E2%80%93Lehmer_primality_test#Time_complexity

@make-github-pseudonymous-again
Copy link
Member Author

This also works for numbers of the form R-c:

Let x = hi * R + lo, then x = hi * (R-c) + c * hi + lo = c * hi + lo (mod R-c).

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

No branches or pull requests

1 participant