1、每次计算只要取最后一位即可。
2、使用快速幂提高效率。
#include<iostream> using namespace std;int pow(int a,int n){if(n==1)return a;else if(n%2==1)return (a*pow(a,n-1))%10;else{int tmp;tmp=pow(a,n>>1);return (tmp*tmp)%10;}}int main() { int T,n;cin>>T;while(T–){cin>>n;cout<<pow(n%10,n)<<endl;}return 0; }
,努力爱一个人。付出,不一定会有收获;