春晚魔术[蓝桥]
这里
考虑到N很大则快速幂无法处理,因为它并没有被取模
欧拉定理:
当是质数时
是质数
两边同时取mod,
//
// Created by yumo_
//
#include<bits/stdc++.h>
using namespace std;
#define scin std::cin
#define scout std::cout
using i64=long long;
const int INF=INT_MAX/2;
const i64 INFF=LLONG_MAX/2;
const i64 md=1e9+7;
const int M=1e5+7;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
scin>>T;
// T=1;
for (;T>0;--T) {
i64 A,B,C;scin>>A>>B>>C;
auto pow=[&](i64 a,i64 b,i64 Md) {
i64 res=1;
while (b>0) {
if (b&1) res=res*a%Md;
a=a*a%Md;
b>>=1;
}
return res;
};
i64 N;scin>>N;N=pow(2,N,md-1);
i64 ans=pow(A,N,md)*pow(B,N,md);ans%=md;
ans=ans*pow(C,N,md);ans=ans%md;
scout<<ans<<"\n";
}
// 18 22 24
return 0;
}