Last active
December 23, 2015 04:19
-
-
Save iseki-masaya/6579331 to your computer and use it in GitHub Desktop.
MOD乗算のコード
・if文で分岐させることでモジュロ演算をしない(PGOが備わってれば分岐数の少ないif文は低コスト)
・bit毎に確認するので計算量はO(log(N))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int MOD = 1000000007; | |
long long | |
mod_mult(long long a,long long b) | |
{ | |
long long res = 0; | |
long long mir = a%MOD; | |
while (b) { | |
if (b&1) { | |
res += mir; | |
if (res > MOD) { | |
res -= MOD; | |
} | |
} | |
mir <<= 1; | |
if (mir > MOD) { | |
mir -= MOD; | |
} | |
b >>= 1; | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment