所以:(A+B)*k^( euler(n) /2 * n),应该不会T。不过还是用了快速幂。
思考:这次应该是在牛客网打的最好的一次了吧。最后排名31。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
//#define p1 first
//#define p2 second
//memset(a, 0, sizeof(a));
//stack堆栈 queue队列 priority_queue优先队列
//vector向量 multiset平衡二叉树 deque双端队列
//pair{T1 first;T2 second;} greater<T>
//unordered_map 哈希map
set<int> s;
const int mod=1e9+7;
//快速乘法(a*b)%mod
LL quick_mul(LL a, LL b)
{
LL ans=0;
while(b)
{
if(b&1)
ans=(ans+a)%mod;
a=(a+a)%mod;
b>>=1;
}
return ans;
}
//快速幂(a^b)%mod
LL quick_pow(LL a, LL b)
{
LL ans=1;
while(b)
{
if(b&1)
ans=quick_mul(ans, a);
a=quick_mul(a, a);
b>>=1;
}
return ans;
}
LL euler(LL n)
{
LL res=n;
for(LL i=2;i*i<=n;i++)
{
if(n%i==0)//第一次找到的必为素因子
res=res/i*(i-1);
while(n%i==0)//把该素因子全部约掉
n/=i;
}
if(n>1)
res=res/n*(n-1);
return res;
}
int main()
{
int n, k, A, B, ans=0;
scanf("%d%d%d%d",&n,&k,&A,&B);
ans=euler((LL)n);
ans=(ans/2)*n;
printf("%lld\n",((A+B)*quick_pow(k, ans))%mod);
return 0;
}