Skip to content

Instantly share code, notes, and snippets.

@harveytoro
Created November 22, 2012 11:25
Show Gist options
  • Save harveytoro/4130673 to your computer and use it in GitHub Desktop.
Save harveytoro/4130673 to your computer and use it in GitHub Desktop.
Modular Exponentiation Java method
public static int modpow(int value , int power, int mod){
int e = 1;
for (int i = 0; i < power; i++) {
e = ((e * value) % mod);
}
return e;
}//modpow
/*
((value^power)%mod)
call as modpow(value, power, mod);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment