编程介的小学生 2017-06-01 16:33 采纳率: 20.5%
浏览 1016
已采纳

A hard puzzle

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

  • 写回答

4条回答 默认 最新

  • SuperKilling 2017-06-02 09:12
    关注

    Yes of cause the upstair solution is OK, but if you want to know why the number like that in array "sam" like that, you can reference my LastBitNumber function.
    This function is applied to any modulo not only 10, I've test my program just now, and fix some bug, you can press enter and press controll + Z to end the input. here is the program

    #include "stdafx.h"
    #include
    #include

    using namespace std;

    // actually it can calculate any modulo last bit, here called this function with modulo = 10
    unsigned int Fun_LastBitNumber(unsigned int a, long int exponet, unsigned int modulo)
    {
    long int i = 0;
    unsigned int remainder = 0, temp = 1, remainder_a = 0;

    remainder_a = a % modulo;
    
    for (i = 0; i < exponet; i++)
    {
        temp *= remainder_a;
        remainder = temp % modulo;
        temp = remainder;
    }
    
    return remainder;
    

    }

    int _tmain(int argc, _TCHAR* argv[])
    {
    unsigned int a = 0, lastbitNumber = 0, modulo = 10;// binary octal hexadecimal are also OK;
    long int exponet = 0;
    std::vector vecLastBitNum;
    std::vector::iterator itervecLastBitNum;

    while(cin >> a >> exponet)
    {
        lastbitNumber = Fun_LastBitNumber(a, exponet, modulo);
        vecLastBitNum.push_back(lastbitNumber);
    }
    
    //Output
    itervecLastBitNum = vecLastBitNum.begin();
    while( itervecLastBitNum != vecLastBitNum.end() )
    {
        cout << *itervecLastBitNum << endl;
        itervecLastBitNum++;
    }
    return 0;
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料