QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142302 | #5661. Multi-Ladders | ammardab3an# | AC ✓ | 1ms | 3452kb | C++17 | 1.5kb | 2023-08-18 22:10:47 | 2023-08-18 22:10:49 |
Judging History
answer
#include <bits/stdc++.h>
#define int int64_t
#define endl '\n'
using namespace std;
const int MOD = 1e9 + 7;
int add(int a, int b){
int ret = (a*1ll + b) %MOD;
if(ret < 0 ) ret += MOD;
return ret;
}
int mul(int a, int b){
int ret = (a*1ll * b)%MOD;
if(ret < 0) ret += MOD;
return ret;
}
int pow_exp(int n, int p){
if(!p) return 1;
if(p&1) return mul(n, pow_exp(n, p-1));
int ret = pow_exp(n, p/2);
return mul(ret, ret);
}
int inv(int n){
return pow_exp(n, MOD-2);
}
int calc(int st, int q, int n){
// if(n <= 0) return 0;
int a0 = add(pow_exp(q, n), -1);
int a1 = add(q, -1);
int a = mul(a0, inv(a1));
return mul(st, a);
}
int32_t main()
{
int t; cin >> t; while(t--){
int n, k, l;
cin >> n >> k >> l;
if(l < 2){
cout << 0 << endl;
continue;
}
int a0 = mul(l-2, l-2);
int a1 = add(a0, l-1);
int a = pow_exp(a1, ((n-1)*k) % (MOD-1));
int b0 = calc(mul(l-1, l-1), mul(l-1, l-1), (k-1)/2);
int b1 = calc(l-1, mul(l-1, l-1), k/2);
int b = k%2==1 ? add(b0, -b1) : add(b1, -b0);
b = mul(b, l);
// int b0 = calc(pow_exp(l-1, k-1), inv(mul(l-1, l-1)), (k-1)/2 + 1);
// int b1 = calc(pow_exp(l-1, k-2), inv(mul(l-1, l-1)), (k-2)/2 + 1);
int ans = mul(a, b);
// cout << a << ' ' << b << endl;
cout << ans << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3452kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3400kb
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