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;
    }

    运行截图:


  • 相关阅读:
    广商14级软件工程团队第一次冲刺相关问题
    Github团队开发示例(二)
    广商14级软件工程团队作业分数
    Github团队开发示例(一)
    《Head First 设计模式》之装饰者模式
    《Head First 设计模式》之观察者模式
    《Head First 设计模式》之策略模式
    AD域登录验证
    广商14级软件工程:助教总结
    广商14级软件工程分数:第十四回合
  • 原文地址:https://www.cnblogs.com/sr1993/p/3697824.html
Copyright © 2011-2022 走看看