Rightmost Digit
2 3 4
7 6HintIn the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7. In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.
找到这个规律,这道题就不难了。不然一点思路没有。
代码如下:
#include<cstdio>
int main(){
int t,n,f[10][10]={{1,0},{1,1},{4,2,4,8,6},{4,3,9,7,1},{2,4,6},{1,5},{1,6},{4,7,9,3,1},{4,8,4,2,6},{2,9,1}};
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int m=n%f[n%10][0];
if(!m) m=f[n%10][0];
printf("%d\n",f[n%10][m]);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 1061.Rightmost Digit【数论及方法】【8月30】
原文地址:http://blog.csdn.net/a995549572/article/details/48104105