QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#110373 | #5661. Multi-Ladders | ycccc319# | AC ✓ | 2ms | 3520kb | C++23 | 1.9kb | 2023-06-01 18:25:21 | 2023-06-01 18:25:22 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
const ll mod =(int)1e9+7;
using namespace std;
ll inv(ll i)
{
if (i == 1)
return 1;
return (mod - mod / i) * inv(mod % i) % mod;
}
inline ll qMul(ll a, ll b, ll mod)
{
ll tmp = (a * b - (ll)((long double)a / mod * b + 1.0e-8) * mod);
return tmp < 0 ? tmp + mod : tmp;
}
// 快速幂
ll qPow(ll base, ll power, ll mod)
{
ll ans = 1;
while (power)
{
if (power & 1)
{
ans = qMul(ans, base, mod);
}
base = qMul(base, base, mod);
power >>= 1;
}
return ans % mod;
}
ll g(ll n,ll k,ll x)
{
ll o=(x-2)*(x-3)%mod+2*(x-1)%mod-1;
o=o%mod;
ll gg= qPow(o,n-1,mod);
ll ggg= qPow(gg,k,mod);
return ggg%mod;
}
ll f(ll k,ll x)
{
ll ans=x* qPow(x-1,k-1,mod)%mod;
return ans;
}
ll ans_k(ll n,ll k,ll x)
{
ll ans_3=x*(x-1)%mod*(x-2)%mod;
if(k==3)
{
return ans_3;
}
ll a1=f(4,x);
if(k==4)
{
return ((a1-ans_3)%mod+mod)%mod;
}
ll q=-(x-1);
q=q%mod+mod%mod;
ll S=a1*(1- qPow(q,k-3,mod))%mod*inv(((1-q)%mod+mod)%mod)%mod;
if(k&1)
{
S=((-S)%mod+mod)%mod;
return ((S+ans_3)%mod+mod)%mod;
}
else
{
return ((S-ans_3)%mod+mod)%mod;
}
}
int main()
{
int l;
cin>>l;
while (l--)
{
ll n,k,x;
cin>>n>>k>>x;
if(x<=1)
{
cout<<0<<"\n";
continue;
}
if(x==2)
{
if(k&1)
{
cout<<0<<"\n";
continue;
}
else
{
cout<<2<<"\n";
continue;
}
}
ll ans=g(n,k,x)*ans_k(n,k,x)%mod;
cout<<ans<<"\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3316kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3520kb
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