QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#549748 | #5661. Multi-Ladders | Tiga_Pilot_2# | AC ✓ | 0ms | 3668kb | C++20 | 1.6kb | 2024-09-06 20:56:12 | 2024-09-06 20:56:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(a, b) for (int i = (int) a; i < (int) b; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const ll mod = 1e9+7;
ll fastexpo(ll a, ll b, ll md = mod) {
ll res = 1;
while(b) {
if(b&1) {
res = (res * a)%md;
}
a = (a * a)%md;
b >>= 1;
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int L;
cin >> L;
while(L--) {
ll n, k, p;
cin >> n >> k >> p;
if(p <= 1) {
cout << 0 << "\n";
} else {
ll a = fastexpo((p-1)%mod, k);
ll b = fastexpo((mod-1), k);
ll c = (p-1)%mod;
// ll d = fastexpo(p, mod-2);
ll cyc_color = (b * c)%mod;
cyc_color = (cyc_color + a)%mod;
// cyc_color = (cyc_color * d)%mod;
if (n == 1) {
cout << cyc_color << "\n";
} else {
ll e = ((p-1)%mod * (p-1)%mod)%mod;
e = ((e - p + mod)%mod + 2)%mod;
ll f = (n-1 + mod-1)%(mod-1);
f = (f * k)%(mod-1);
// cout << e << " " << f << "\n";
ll ladder = fastexpo(e, f);
// cout << cyc_color << "\n";
ll ans = (cyc_color * ladder)%mod;
cout << ans << "\n";
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3668kb
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