十进制快速幂

用于指数爆longlong的情况,当然你也可以打高精……

#include<iostream>
#include<cstring>
#include<cstdio>
#define LL long long
using namespace std;
char c[100000];
LL a,p,t;
LL tenthpow(LL a)
{
    LL ans=1,s=a;
    while(t>=0)
    {
        LL cnt=c[t]-'0',cur=s;
        for(int i=1;i<=cnt;i++)
        ans=ans*s%p;
        for(int i=1;i<10;i++)
        cur=cur*s%p;
        s=cur;ans%=p;t--;
    }
    return ans;
}
signed main()
{
    cin>>a>>c>>p;
    t=strlen(c);t--;
    cout<<tenthpow(a)<<endl;
}

 

posted @ 2019-07-15 19:10  xukl21  阅读(122)  评论(0编辑  收藏  举报