AcWing 90. 【Java】64位整数乘法
原题链接
简单
作者:
tt2767
,
2019-12-02 22:28:57
,
所有人可见
,
阅读 785
// python 切回java 总是忘了 ; 😂
// 要用 nextLong
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws Exception{
Scanner jin = new Scanner(System.in);
long a = jin.nextLong();
long b = jin.nextLong();
long p = jin.nextLong();
System.out.println(mul(a, b, p));
}
public static long mul(long a, long b, long p){
long res = 0;
while (b != 0){
if ((b&1) == 1 ){
res = (res + a) % p;
}
a = a * 2 % p;
b >>= 1;
}
return res;
}
}