您的位置:首页 > 其它

ACM课-Rightmost Digit-规律

2017-05-17 19:39 351 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: