蒟蒻快速幂求助!!!
查看原帖
蒟蒻快速幂求助!!!
494192
ChickenDrinkingMilk楼主2022/6/15 20:51
/*_____luogu P1226 【模板】快速幂||取余运算_____*/
/*_____快速幂 递归+for循环 qwq_____*/ 
#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
ll x,y,p;
ll pow1(ll x,ll y,ll p){
	ll ans=1;
	for (;y>0;y>>=1){
		if (y&1) ans=ans*x%p;
		ans=ans*ans%p;
	}
	return ans%p;
}
int main(){
	cin>>x>>y>>p;
	cout<<x<<"^"<<y<<" mod "<<p<<"="<<pow1(x,y,p);
	return 0;
}

21分 WA

2022/6/15 20:51
加载中...