首页 > 其他 > 详细

快速幂

时间:2018-08-23 15:21:20      阅读:167      评论:0      收藏:0      [点我收藏+]
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mn=1e18;
ll pow(ll a,ll b,ll n){
    ll ans=1;
    ll base=a;
    while(b){
        if(b&1) ans=ans*base%n;
        base=base*base%n;
        b>>=1;
    }
    return ans;
}
int main(){
    ll x,y;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin>>x>>y){
        cout<<pow(x,y,mn)<<endl;
    }
    return 0;
}

快速幂

原文:https://www.cnblogs.com/mch5201314/p/9523473.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!