码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1097 A hard puzzle

时间:2015-12-30 21:43:00      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

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);
    }
    
}

 

hdu 1097 A hard puzzle

标签:

原文地址:http://www.cnblogs.com/wangmenghan/p/5089889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!