zoukankan      html  css  js  c++  java
  • 简单的快速幂取模

      HDU1097

    本题为快速幂取模运算,直接套用模板即可

    //题目描述:给你数a,b,让你输出a^b的最后一位

    #include <iostream>
    #include <cstdio>
    using namespace std;
    
    #define  LL long long
     
    LL  pow_mod(LL  a, LL  b)
    {
    	LL  ans = 1;
    	a = a % 10;
    	while (b > 0)
    	{
    		if (b %2)
    			ans = ans * a % 10;
    		b= b >> 1;
    		a = a * a % 10;
    	}
    	return ans;
    }
    
    int main()
    {
    	LL a, b;
    	while (cin >> a >> b)
    	{
    		cout << pow_mod(a, b)<< endl;
    	}
    	return 0;
    }

  • 相关阅读:
    EM
    te2
    te
    XLnet
    GPT
    40.Properties
    38.特殊操作流
    37.I/O流
    35.File
    day68日考
  • 原文地址:https://www.cnblogs.com/Tovi/p/6194866.html
Copyright © 2011-2022 走看看