AcWing 875. 快速幂

题目链接
https://www.acwing.com/problem/content/877/
思路
思路大概就是幂数转化为二进制,然后我们用一个变量记录累乘的结果,然后位权为1的时候我们就将ans更新即可,详情可以看我这一篇博客:https://acmer.blog.csdn.net/article/details/122280910
代码
#include
using namespace std;
#define ll long long

int n;
ll a,b,p;

ll ksm(ll a,ll b,ll p){
ll ans = 1LL;
while(b) {
if(b & 1) ans = (ans * a) % p;
b >>= 1; a = (a * a) % p;
}
return ans;
}

int main()
{
sc

AcWing 875. 快速幂最先出现在Python成神之路

版权声明:
作者:admin
链接:https://www.techfm.club/p/19560.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>