-
Notifications
You must be signed in to change notification settings - Fork 24
Closed
Description
Kotlin版へ移植( https://github.com/da-louis/ac-library-kt/pull/33 )してもらっている際に発見
xが大きいと30行目のx*xでオーバーフローしてしまうようなので、先にmodを取っておく必要がありそうです。
(もしくは第一引数はint型が正しい?)
AtCoderLibraryForJava/Math/MathLib.java
Lines 25 to 34 in 24160d8
| public static long pow_mod(long x, long n, long m){ | |
| assert(n >= 0 && m >= 1); | |
| long ans = 1; | |
| while(n > 0){ | |
| if(n%2==1) ans = (ans * x) % m; | |
| x = (x*x) % m; | |
| n /= 2; | |
| } | |
| return ans; | |
| } |
Metadata
Metadata
Assignees
Labels
No labels