Skip to content

Instantly share code, notes, and snippets.

@st98
Created April 27, 2014 09:28
Show Gist options
  • Save st98/11341424 to your computer and use it in GitHub Desktop.
Save st98/11341424 to your computer and use it in GitHub Desktop.
冪剰余。
var divmod = function (base, exp, mod) {
var result = 1;
while (exp > 0) {
if ((exp & 1) === 1) {
result = result * base % mod;
}
exp >>= 1;
base = base * base % mod;
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment