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

HDOJ 1097 A hard puzzle

时间:2014-05-19 16:05:39      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   class   code   c   

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
 

这道题也是一道求最后一个数字的,只是方式稍微改变了一下...

bubuko.com,布布扣
 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int a,b;
 6     int round=0;
 7     int r[100]={0};
 8     int i=0;
 9     while(cin>>a>>b)
10     {
11         r[1]=a%10;
12         r[2]=(a%10)*(a%10)%10;//这里是关键,开始是a*a%10,提交提示WA。
13         for(i=3;;i++)
14         {
15             r[i]=r[i-1]*(a%10)%10;
16             if(r[i]==r[1])
17             {round=i-1;break;}
18         }
19         if(b%round==0)
20             cout<<r[round]<<endl;
21         else cout<<r[b%round]<<endl;
22     }
23     return 0;
24 }
bubuko.com,布布扣

 

 

HDOJ 1097 A hard puzzle,布布扣,bubuko.com

HDOJ 1097 A hard puzzle

标签:des   style   blog   class   code   c   

原文地址:http://www.cnblogs.com/kb342/p/3735060.html

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