这道题解法多样,我的是劳模做法。下面附一些大神级别的让人脑洞大开的解法。。。
1,、劳模做法:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iomanip>
using namespace std;
const int MAX = 5845;
int main()
{
long long n;
int T;
while(cin>>T)
{
while(T--){
cin>>n;
int x = n%10;
switch(x)
{
case 0: cout<<x<<endl; break;
case 1: cout<<x<<endl; break;
case 2: cout<<((n/10)%2?"6":"4")<<endl; break;
case 3: cout<<((n/10)%2?"3":"7")<<endl; break;
case 4: cout<<"6"<<endl; break;
case 5: cout<<x<<endl; break;
case 6: cout<<x<<endl; break;
case 7: cout<<((n/10)%2?"7":"3")<<endl; break;
case 8: cout<<((n/10)%2?"4":"6")<<endl; break;
case 9: cout<<x<<endl;
}
}
}
return 0;}
某大神叼炸天的打表,可以说是劳模做法的简化版
#include <iostream>
using namespace std;
int main(){
int n,m;
int a[10][4] = {{0,0,0,0},{1,1,1,1},{2,4,8,6},{3,9,7,1},{4,6,4,6},{5,5,5,5},{6,6,6,6},{7,9,3,1},{8,4,2,6},{9,1,9,1}};
cin>>m;
while(m--)
cin>>n,cout<<a[n%10][n%4-1>=0?n%4-1:3]<<endl;
return 0;
}
int solve(int n,int m){
if(m==0) return 1;
if(m==1) return n;
if(m%2==0) return solve(n*n%10,m/2);
if(m%2!=0) return n*solve(n*n%10,(m-1)>>2)%10;
}