hdu 1097 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(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
题目意思就是求给定两数的次方,然后取最后一位;
我的想法:决定最后一位的只有最后一位数,所以首先对求a对10求余的数值并赋给a,其次通过找规律得到,每4次一循环,所以求b对4求余的数值并赋给b;接下来应该都懂了,代码如下;
#include<stdio.h>
#include<math.h>
int main()
{
    int a,b,c,d;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        a=a%10;b=b%4;
        if(b==0)
        b=4;
        c=pow(a,b);
        d=c%10;
        printf("%d\n",d);
    }
    
}

 

posted @ 2015-12-30 19:49  俺叫王梦涵  阅读(164)  评论(0编辑  收藏  举报