QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#269932 | #5661. Multi-Ladders | STnofarjo# | AC ✓ | 1ms | 3344kb | C++20 | 773b | 2023-11-30 11:43:12 | 2023-11-30 11:43:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
ll fpow(ll a, ll b) {
ll ret = 1;
while (b) {
if (b & 1) ret = (ret * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return ret;
}
void solve() {
ll n, k, v;
cin >> n >> k >> v;
if (v <= 1) {
cout << 0 << '\n';
return;
}
ll cyc = fpow(v - 1, k);
ll tmp = ((k & 1) ? -1 : 1);
cyc = (cyc + (v - 1) * tmp) % MOD;
ll sides = ((v - 1) * (v - 1) - (v - 2)) % MOD;
sides = fpow(sides, (n - 1) * k) % MOD;
ll ans = (sides * cyc) % MOD;
if (ans < 0) ans += MOD;
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int tc;
cin >> tc;
for (int i = 0; i < tc; i++) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3344kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3328kb
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