zoukankan      html  css  js  c++  java
  • uva 10515 规律打表

    Problem G Power et al. Input: Standard Input

    Output: Standard Output

    Finding the exponent of any number can be very troublesome as it grows exponentially J. But in this problem you will have to do a very simple task. Given two non-negative numbers and n, you will have to find the last digit of mn in decimal number system.

    Input

    The input file contains less than 100000 lines. Each line contains two integers and n (Less than 10^101). Input is terminated by a line containing two zeroes. This line should not be processed.

    Output

    For each set of input you must produce one line of output which contains a single digit. This digit is the last digit of mn.

     

    Sample Input 

    2 2

    2 5

    0 0                            

    Output for Sample Input

    4

    2

    题目大意:求m^n的最后一位数字

    打表出0、1、2、3、4、5、6、7、8、9(50次方以内的数)

    发现规律,最长的周期为4

    (0) 0 0 0 0

    (1)1 1 1 1

    (2)2 4 8 6

    (3)3 9 7 1

    (4)4 6 4 6

    (5)5 5 5 5

    (6)6 6 6 6

    (7)7 9 3 1

    (8)8 4 2 6

    (9)1 9 1 9

    AC代码:

    #include<iostream>
    #include<cstdio>
    #include<string>
    using namespace std;
    string a,b;
    int f[10][4]=
    {
        0,0,0,0,
        1,1,1,1,
        6,2,4,8,
        1,3,9,7,
        6,4,6,4,
        5,5,5,5,
        6,6,6,6,
        1,7,9,3,
        6,8,4,2,
        1,9,1,9
    };
    
    int deal()
    {
        int p=a[a.size()-1]-'0';
        int i,ret=0;
        for(i=0;i<b.size();i++)
            ret=(ret*10+b[i]-'0')%4;
        return f[p][ret];
    }
    int main()
    {
        while(cin>>a>>b,!(a=="0" && a==b))
        {
            if(b=="0")
                cout<<1<<endl;
            else 
                cout<<deal()<<endl;
        }
        return 0;
    }
  • 相关阅读:
    【Unity 3D】学习笔记29:游戏的例子——简单的小制作地图
    mysql位_01检查错误代码的方法
    编程获取linuxservercpu、内存和磁盘使用
    poj 2482 Stars in Your Window(扫描线)
    Largest Rectangle in Histogram
    【剑指offer】删除字符也出现在一个字符串
    linux sdio card睡眠治疗 sdio card removed解决方案
    Wooyun
    APT攻击
    Elasticsearch 学习~
  • 原文地址:https://www.cnblogs.com/xiong-/p/3218741.html
Copyright © 2011-2022 走看看