HDU1097——A hard puzzle

单存的快速幂取模,就是a^b%c的变形……, 让c=10就可以了

原理:(a*b)%c = (a%c * b%c)%c;

View Code
#include<stdio.h>
int main()
{
__int64 a, b, t;
while(scanf("%I64d%I64d", &a, &b) != EOF )
{
t=1;
while(b)
{
if(b%2==1)
{
t=t*a%10;
}
a=a*a%10;
b /= 2;
}
printf("%I64d\n", t%10);
}
return 0;
}

 

posted @ 2011-11-24 20:10  1050768624  阅读(156)  评论(0编辑  收藏  举报