72分的蒟蒻
查看原帖
72分的蒟蒻
654164
JoshuaZheng楼主2022/3/22 21:08

为什么最后两个样例过不了啊。呜呜呜~

#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
typedef double dou;
typedef unsigned long long ull;
const int maxn=2e5+3;
ull a,b,c,ans=0;
ull solve(ll b)
{
    if(b==0)return 1;
    if(b==1)return a%c;
    if(b%2==0)return (ull)pow(solve(b/2)%c,2);
    else {return (a%c)*(ull)pow(solve((b-1)/2)%c,2);}
}
int main()
{
    cin>>a>>b>>c;
    ans=solve(b);
    cout<<a<<'^'<<b<<" mod "<<c<<'='<<ans%c;
    return 0;
}
2022/3/22 21:08
加载中...