快速幂模板
原理如下
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;
}
}