zoukankan      html  css  js  c++  java
  • [ACM

    A hard puzzle

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
    Total Submission(s) : 25   Accepted Submission(s) : 7

    Font: Times New Roman | Verdana | Georgia

    Font Size:  

    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



    解题思路:

    一个数不管多大,我们关心的只是它的个位数,它再几次方也只关心个位的数字,个位数字0到9次方找周期,辅助图如下:


    根据规矩,可以很容易写出代码。


    代码:

    #include <iostream>
    using namespace std;
    int main()
    {
        int a,b;
        while(cin>>a>>b)
        {
    
                int t;
                t=a%10;//t为个位数
                switch(t)
                {
                    case 0:{cout<<0<<endl;break;}
                    case 1:{cout<<1<<endl;break;}
                    case 2:
                        {
                        if(b%4==1)
                            cout<<2<<endl;
                        else if(b%4==2)
                            cout<<4<<endl;
                        else if(b%4==3)
                            cout<<8<<endl;
                        else if(b%4==0)
                            cout<<6<<endl;
                        break;
    
                        }
                    case 3:
                        {
                            if(b%4==0)
                                cout<<1<<endl;
                            else if(b%4==1)
                                cout<<3<<endl;
                            else if(b%4==2)
                                cout<<9<<endl;
                            else if(b%4==3)
                                cout<<7<<endl;
                            break;
                        }
                    case 4:
                        {
                            if(b%2==1)
                                cout<<4<<endl;
                            if(b%2==0)
                                cout<<6<<endl;
                            break;
                        }
                    case 5:{cout<<5<<endl;break;}
                    case 6:{cout<<6<<endl;break;}
                    case 7:
                        {
                            if(b%4==0)
                                cout<<1<<endl;
                            else if(b%4==1)
                                cout<<7<<endl;
                            else if(b%4==2)
                                cout<<9<<endl;
                            else if(b%4==3)
                                cout<<3<<endl;
                            break;
                        }
                    case 8:
                        {
                            if(b%4==0)
                                cout<<6<<endl;
                            else if(b%4==1)
                                cout<<8<<endl;
                            else if(b%4==2)
                                cout<<4<<endl;
                            else if(b%4==3)
                                cout<<2<<endl;
                            break;
                        }
                    case 9:
                        {
                            if(b%2==0)
                                cout<<1<<endl;
                            else if(b%2==1)
                                cout<<9<<endl;
                            break;
                        }
                }
        }
        return 0;
    }

    运行截图:


  • 相关阅读:
    8.Eclipse中创建Maven Web项目
    spin_lock &amp; mutex_lock的差别?
    如花搞笑图片集锦(转贴)
    二分查找
    WebStorm 7.0 注冊码
    Sphinx/Coreseek 4.1 跑 buildconf.sh 一个错误,无法生成configure档
    可变长度结构
    于linux已安装moodle
    采用WindowManager添加您自己的自定义视图
    mysql1130远程连接没有权限解决方法
  • 原文地址:https://www.cnblogs.com/sr1993/p/3697824.html
Copyright © 2011-2022 走看看