HDU1061 Rightmost Digit (快速幂)
程序员文章站
2022-07-05 17:01:25
...
快速幂模板
原理如下
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static long n, T;
public static void main(String[] args) throws IOException {
T = Long.parseLong(br.readLine());
for (int i = 0; i < T; i++) {
n = Long.parseLong(br.readLine());
System.out.println(qmi(n, n, 10));
}
}
private static long qmi(long a, long k, int q) {
long res = 1;
while (k > 0) {
if ((k & 1) == 1) res = res * a % q;
k >>= 1;
a = a * a % q;
}
return res;
}
}
上一篇: 你这样好像在喂狗
下一篇: 任天堂:Switch不太可能兼容VR内容