A - A hard puzzle解题报告

A - A hard puzzle
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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直接计算,第二个就是要注意余数的循环,其他的应该没有什么问题了。


[cpp]  view plain copy
  1. #include<iostream>  
  2. using namespace std;  
  3. int main()  
  4. {  
  5.     int a,b,i,j=2,num,c[1000];  
  6.     while(cin>>a>>b)  
  7.     {  
  8.         a=a%10;  
  9.         c[1]=a;  
  10.         num=a;  
  11.         for(i=2;i<=b;i++)  
  12.         {  
  13.             num=num*a%10;  
  14.             if(num==a)  
  15.                 goto next;  
  16.             else  
  17.                 c[i]=num;  
  18.         }  
  19. next:  
  20.         j=b%(i-1);  
  21.         if(j==0)  
  22.             j=j+i-1;  
  23.         cout<<c[j]<<endl;  
  24.     }  
  25.     return 0;  
  26. }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值