都是找规律的题,代码几乎一样,好像快速幂取模也能解;
1061
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int result[][5]={{0,0,0,0,0},{0,1,1,1,1},{0,2,4,8,6},{0,3,9,7,1},{0,4,6,4,6},{0,5,5,5,5},{0,6,6,6,6},{0,7,9,3,1},{0,8,4,2,6},{0,9,1,9,1}};
int max,enter,endEnter;
cin>>max;
while(max--){
cin>>enter;
endEnter=enter%10;
cout<<result[endEnter][enter%4==0?4:enter%4]<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
1097
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int result[][5]={{0,0,0,0,0},{0,1,1,1,1},{0,2,4,8,6},{0,3,9,7,1},{0,4,6,4,6},{0,5,5,5,5},{0,6,6,6,6},{0,7,9,3,1},{0,8,4,2,6},{0,9,1,9,1}};
int enterA,enterB;
while(cin>>enterA>>enterB){
enterA%=10;
cout<<result[enterA][enterB%4==0?4:enterB%4]<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}