A^B Problem
时间限制:
1000 ms | 内存限制:
65535 KB
难度:
2
-
描述
-
Give you two numbers a and b,how to know the a^b's the last digit number.It looks so easy,but everybody is too lazy to slove this problem,so they remit to you who is wise.
-
输入
- There are mutiple test cases. Each test cases consists of two numbers a and b(0<=a,b<2^30) 输出
- For each test case, you should output the a^b's last digit number. 样例输入
-
7 66 8 800
样例输出
-
9 6
提示
There is no such case in which a = 0 && b = 0。
#include<cstdio> #include<cstdlib> #include<cstring> using namespace std; int main() { int i,n,m,k,ans,t,vis[15],a[15]; while(scanf("%d%d",&n,&m)==2){ k=n%10;ans=1;t=0; memset(vis,0,sizeof(vis)); if(m==0){ printf("1\n");continue; } else if(n==0){ printf("0\n");continue; } for(i=0;i<m;++i){ ans=ans*k%10; if(vis[ans]==0){ vis[ans]=1; a[t]=ans; t++; } else break; } if(i==m)printf("%d\n",ans); else printf("%d\n",a[(m-1)%t]); } return 0; }