hdu-1097 A hard puzzle

A hard puzzle
Problem Description
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin. this puzzle describes that: gave a and b,how to know the a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0Output
For each test case, you should output the a^b's last digit number.
Sample Input
7 66
8 800
 
Sample Output


제목: 이 문제는 a^b의 개위 숫자를 구한다.(0#include<iostream> using namespace std; int main() { int a,b,ans; while(scanf("%d%d",&a,&b)!=EOF) { int x[4]; // , 1~4 int n; if(a>=10) a%=10; // , switch(a) { case 0:ans=0;break; case 1:ans=1;break; case 2:x[0]=2;x[1]=4;x[2]=8;x[3]=6;n=b%4;if(n==0) n=4;ans=x[n-1];break; // , ; if(n==0) n=4;ans=x[n-1] .... case 3:x[0]=3;x[1]=9;x[2]=7;x[3]=1;n=b%4;if(n==0) n=4;ans=x[n-1];break; case 4:x[0]=4;x[1]=6;n=b%2;if(n==0) n=2;ans=x[n-1];break; case 5:ans=5;break; case 6:ans=6;break; case 7:x[0]=7;x[1]=9;x[2]=3;x[3]=1;n=b%4;if(n==0) n=4;ans=x[n-1];break; case 8:x[0]=8;x[1]=4;x[2]=2;x[3]=6;n=b%4;if(n==0) n=4;ans=x[n-1];break; case 9:x[0]=9;x[1]=1;n=b%2;if(n==0) n=2;ans=x[n-1];break; } printf("%d
",ans); } return 0; }

좋은 웹페이지 즐겨찾기