编程介的小学生 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条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码