#include<iostream> using namespace std; int main() { int N, b; //0 1 5 6 多少次方都不变(0次方除外) //arr记录0-9 2次方开始的规律 int arr[10][4]={0,0,0,0, 1,1,1,1, 6,2,4,8, 1,3,9,7, 6,4,6,4, 5,5,5,5, 6,6,6,6, 1,7,9,3, 6,8,4,2, 1,9,1,9 }; while(scanf("%d",&N)) { if(N==0) printf("1\n"); else { b=N%10; if(b==0||b==1||b==5||b==6) printf("%d\n",arr[b][0]); else if(b==2||b==3||b==7||b==8) printf("%d\n",arr[b][N%4]); else printf("%d\n",arr[b][N%2]); } } } |
Double click to view unformatted code.