A hard puzzleTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 49940 Accepted Submission(s): 18357 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.
Input There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
Output For each test case, you should output the a^b's last digit number.
Sample Input 7 66 8 800
Sample Output 9 6
Author eddy
|
#include<cstdio>
#include<algorithm>
using namespace std;
long long shu(long long n,long long m) //快速幂。注意变量定义为long long 型
{
long long result=1,a=n,b=m,i;
while(b)
{
if(b%2!=0)
result=result*a%10;
a=a*a%10;
b=b/2;
}
return result;
}
int main()
{
long long n,m;
while(~scanf("%lld%lld",&n,&m))
{
printf("%lld\n",shu(n,m));
}
}