ACM课-Rightmost Digit-规律

来源:互联网 发布:万讯网络中控 编辑:程序博客网 时间:2024/06/12 23:41

n^n的最右边的数。
以前是打的大数的板子写的,后来发现如果时限要求的在短点,也可以用规律,。
手写出来,发现有规律。

#include <iostream>#include <cstdio>using namespace std;int a[10][6]={{0},{1},{6,2,4,8},{1,3,9,7},{6,4},{5},{6},{1,7,9,3},{6,8,4,2},{1,9}};int main(){   int n;int t;    cin>>n;    while(n--)    {  cin>>t;       int m=t%10;       int s;       if(m==1||m==5||m==6) s=1;       else if(m==2||m==3||m==7||m==8) s=4;       else if(m==4||m==9) s=2;        printf("%d\n",a[t%10][t%s]);    }    return 0;}
原创粉丝点击