矩阵快速幂的学习:
https://blog.csdn.net/wust_zzwh/article/details/52058209
n>>1是指n的二进制数向右移一位
n&1等价n%2
https://vjudge.net/contest/231312#problem/F
#include<iostream> #include<stdio.h> #include<string.h> #include<cmath> typedef long long ll; using namespace std; ll ans=1; void quickpow(ll x,ll n) { ll res=x; while(n) { if(n%2==1) { ans*=res; res*=res; if(ans>9) ans=ans%10; if(res>9) res=res%10; } else { res*=res; if(res>9) res=res%10; } n=n>>1; } } int main() { int t; scanf("%d",&t); while(t--) { ans=1; ll n; scanf("%I64d",&n); quickpow(n,n); printf("%I64d ",ans); } return 0; }