数学問題のゴールデンチャネル

https://ac.nowcoder.com/acm/contest/317/D高速パワーのオイラー関数を使用した
小さなaのゴールデンチャネル

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9+7;
ll phi(ll n)   //求欧拉函数值
{
    int ans=n,temp=n;
    for(int i=2;i*i<=temp;i++)
    {
        if(temp%i==0)
        {
            ans-=ans/i;
            while(temp%i== 0) temp/=i;
        }
    }
    if(temp>1) ans-=ans/temp;
    return ans;
}
ll mod_pow(ll x,ll n,ll mod)  //快速幂
{
    ll ans=1;
    while(n)
    {
        if(n%2==1) ans=ans*x%mod;
        x=x*x%mod;
        n/=2;
    }
    return ans;
}
ll a,c;
ll n,k,A,B;
char b[1000010];
int main()
{
    while(~scanf("%lld%lld%lld%lld",&n,&a,&A,&B))
    {
        c=A+B;
        ll res=0,ans;
        res=phi(n)*n/2;
        ans=mod_pow(a,res,mod)*c%mod;
        cout<<ans<<endl;
    }
    return 0;
}

おすすめ

転載: blog.csdn.net/qq_43458555/article/details/86601699