Problem Descriptionlcy gives a hard puzzle to feng5166,lwg,jgshining and ignatius:gave A and b,how to know the A^b.everyb Ody 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 was too lazy to slove the problem,so they remit to you, who was wise.
Inputthere is mutiple test cases. Each test cases consists of numbers a and B (0<a,b<=2^30)
Outputfor Each test case, you should output of the a^b ' s last digit number.
Sample INPUT7 668 800
Sample Output96
Topic Analysis:
1^1=1 1^2=1 1^3=1 1^4=1 1^5=1 ... Starting from 4 cycles to 1
2^1=2 2^2=4 2^3=8 2^4=6 2^5=2 ... Starting from 4 cycles to 4
3^1=3 3^2=9 3^3=7 3^4=1 3^5=3 ... Starting from 4 cycles to 4
4^1=4 4^2=6 4^3=4 4^4=6 4^5=4 ... Starting from 4 cycles to 2
...
9^1=9 9^2=1 9^3=9 9^4=1 9^5=9 ... Starting from 4 cycles to 2
At the same time, to understand that the result of the same power-side mantissa under the title (A%10) and A is the same,
#include <stdio.h>
Main ()
{
int a,b,c;
while (~SCANF ("%d%d", &a,&b))
{
B%=4;a%=10;c=a;
if (b==0)
b=4;
while (--b)
c=c*a%10;
printf ("%d\n", c);
}
}
Hangzhou Electric 1097-a Hard Puzzle