【板子】快速幂

//lg 1226
//快速幂
#include<bits/stdc++.h>
using namespace std;

long long a,n,p;

long long nn;

long long qpow()
{
    long long b=a;
    long long ans=1;
    while(n)
    {
        if(n&1) ans=ans*b%p;
        n/=2;
        b=b*b%p;
    }
    return ans;
}

int main()
{
    // freopen("working.in","r",stdin);
    // freopen("working.out","w",stdout);
    cin>>a>>n>>p;
    nn=n;
    printf("%lld^%lld mod %lld=%lld",a,nn,p,qpow());
    return 0;
}
posted @ 2024-01-26 20:59  yeyou26  阅读(5)  评论(0编辑  收藏  举报