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

hdu 1097 A hard puzzle

时间:2015-09-17 19:00:37      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

A hard puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 35099    Accepted Submission(s): 12610


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
 

 

Author
eddy
 

 

Recommend
JGShining   |   We have carefully selected several similar problems for you:  1170 1164 1087 1032 1062 
 
和以前做的一道题几乎一样,上一次是求N^N的个位数,这次是求a^b的个位数,不过过程其实是一样的。。
 
题意:求a^b的个位数。
 
附上代码:
 
 1 #include <iostream>
 2 using namespace std;
 3 int s[5];
 4 void add(int t)
 5 {
 6     int i,k=1;
 7     for(i=1; i<=4; i++) //通过打表找规律,发现a^b的个位数字4个一循环,而且只需要保存个位数
 8     {
 9         k=k*t%10;
10         s[i]=k;
11     }
12 }
13 int main()
14 {
15     int a,b,i,k;
16     while(cin>>a>>b)
17     {
18         if(b==0)
19         {
20             cout<<1<<endl;
21             continue ;
22         }
23         a=a%10;
24         add(a);
25         k=b%4;
26         if(k==0)
27             cout<<s[4]<<endl;
28         else
29             cout<<s[k]<<endl;
30     }
31     return 0;
32 }

 

hdu 1097 A hard puzzle

标签:

原文地址:http://www.cnblogs.com/pshw/p/4816879.html

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