QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85734 | #5661. Multi-Ladders | zhangboju# | AC ✓ | 2ms | 3736kb | C++14 | 764b | 2023-03-08 09:27:41 | 2023-03-08 09:27:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x)
{
x=0;short f=1;char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
x*=f;return;
}
const int mod=1e9+7;
#define ll long long
int qpow(ll a,ll k)
{
a%=mod;
int res=1;
while(k)
{
if(k&1) res=1ll*res*a%mod;
a=1ll*a*a%mod;
k>>=1;
}
return res;
}
int n,k,p;
int main()
{
int T;read(T);
while(T--)
{
read(n),read(k),read(p);
if(p<2) puts("0");
else
{
int ans=qpow(p-1,k);
if(k&1) ans=(ans-(p-1)+mod)%mod;
else ans=(ans+p-1)%mod;
ans=1ll*ans*qpow(1ll*(p-2)*(p-2)+p-1,1ll*(n-1)*k)%mod;
printf("%d\n",ans);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3520kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3736kb
input:
20 2 3 3 1 3 3 10 3 0 10 3 2 1 21 2 1 22 0 2000 15000 2000 12000 30000 200000 1000000000 3 3 2 1000000000 3 2 3 100000000 1000000000 1000000000 10 1000000000 3 100000000 2 1000000000 100000000 1 1000000000 10 1 1000000000 100000000 1 1000 100000000 1000000000 1000000000 0 1000000000 1000000000 1 100...
output:
162 6 0 0 0 0 349400141 243010659 52489881 53690844 176686901 218103365 558243892 991895211 693053429 883715672 80402569 0 0 311752813
result:
ok 20 lines