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<iostream> #include<vector> #include<string> #include<stack> #include<cstring> #include<stdio.h> #include<stdlib.h> #include<algorithm> using namespace std; int main() { int a,b; int x[4]={6,2,4,8}; int y[4]={1,3,9,7}; int z[2]={6,4}; int w[4]={1,7,9,3}; int v[4]={6,8,4,2}; int u[2]={1,9}; while(~scanf("%d%d",&a,&b)) { if(a==0&&b==0) { break; } int c=a%10; if(b==0) { cout<<"1"<<endl;continue; } switch(c) { case 1: cout<<"1"<<endl;break; case 2: cout<<x[b%4]<<endl;break; case 3: cout<<y[b%4]<<endl;break; case 4: cout<<z[b%2]<<endl;break; case 5: cout<<"5"<<endl;break; case 6: cout<<"6"<<endl;break; case 7: cout<<w[b%4]<<endl;break; case 8: cout<<v[b%4]<<endl;break; case 9: cout<<u[b%2]<<endl;break; case 0: cout<<"0"<<endl;break; } } }
点击打开链接