扩展欧拉定理—降幂大法

a的b的c次方模1e9+7

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define PI 3.1415926535898
#define e 2.718281828459
using namespace std;
const long long Mod=1e9+7;
long long phi(long long x)
{
    long long res=x,a=x;
    for(int i=2;i*i<=a;i++)
    {
        if(a%i==0)
        {
            res=res/i*(i-1);
            while(a%i==0)
                a=a/i;
        }
    }
    if(a>1)
        res=res/a*(a-1);
    return res;
}
long long quickmi(long long x,long long y,long long m)
{
    long long res;
    x=x%m;
    res=1;
    while(y>0)
    {
        if(y%2!=0)
            res=(res*x)%m;
            y=y/2;
            x=(x*x)%m;
    }
    return res%m;
}
int main()
{
    long long a,b,c;
    long long k=phi(Mod);
    while(cin>>a>>b>>c)
    {
        long long s=quickmi(b,c,k);
        long long g=quickmi(a,s+k,Mod);
        cout<<g<<endl;
    }
}
原文地址:https://www.cnblogs.com/Leozi/p/10835203.html