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

issue about fast power #1

Open
yuansip opened this issue Dec 30, 2016 · 0 comments
Open

issue about fast power #1

yuansip opened this issue Dec 30, 2016 · 0 comments

Comments

@yuansip
Copy link

yuansip commented Dec 30, 2016

when n is odd, your code is as below:
// odd case
// a(bc) mod n = ((a mod n)(bc mod n)) mod n
// --> bc mod n = ((b mod n)(c mod n)) mod n
// hMs: half Multiply single
long hMs = ((half % b) * (a % b)) % b;
return (int)((half * hMs) % b);
But I think 'long hMs = (half * (a % b)) % b;' is the right statement.
(a^(n/2) * a^(n/2) * a) mod b = ((a^(n/2) mod b) * ((a^(n/2) * a ) mod b)) mod b
= (half * (((a^(n/2) mod b) * (a mod b)) mod b) mod b
= (half * ((half * (a mod b)) mod b)) mod b

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

No branches or pull requests

1 participant