欧拉函数 牛客寒假1 小a与黄金街道

题目链接

分析:这题用到了欧拉函数,

欧拉函数,用φ(n)表示

欧拉函数是求小于等于n的数中与n互质的数的数目

详细可以看看这篇博文https://www.cnblogs.com/linyujun/p/5194170.html

注意:这种指数形式取模的话不能在指数上直接取模,但可以给底数取模

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int inf=1<<30;
 4 typedef long long ll;
 5 const double pi=acos(-1);
 6 const int mod=1e9+7;
 7 const int maxn=3010;
 8 ll phi(ll x){
 9     ll ans = x;
10     for(int i = 2; i*i <= x; i++){
11         if(x % i == 0){
12             ans = ans / i * (i-1);
13             while(x % i == 0) x /= i;
14         }
15     }
16     if(x > 1) ans = ans / x * (x-1);
17     return ans;
18 }
19 ll pow_mod(ll a, ll b){
20     ll ret = 1;
21     while(b){
22         if(b & 1) ret = (ret * a) % mod;
23         a = (a * a) % mod;
24         b >>= 1;
25     }
26     return ret;
27 }
28 int main(){
29     ll n,k,a,b;scanf("%lld%lld%lld%lld",&n,&k,&a,&b);
30     cout<<((a+b)%mod)*(pow_mod(k%mod,n*phi(n)/2)%mod)%mod<<endl;
31     return 0;
32 }
原文地址:https://www.cnblogs.com/qingjiuling/p/10446698.html