• hdu 1097 A hard puzzle


    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 }
  • 相关阅读:
    Git远程和分支管理
    Git基本使用教程
    linux基础知识总结
    正则表达式-概要
    java注释规范
    JavaScript对象(Object)
    centos7安装docker
    springboot项目问题记录one
    tomcat不需要重启热部署xml文件
    java调用新浪接口根据Ip查询所属地区
  • 原文地址:https://www.cnblogs.com/pshw/p/4816879.html
Copyright © 2020-2023  润新知