QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213823 | #5661. Multi-Ladders | Jeffrey# | AC ✓ | 1ms | 3464kb | C++14 | 1.3kb | 2023-10-14 16:15:59 | 2023-10-14 16:16:00 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b) {
vector<vector<ll>> c(a.size());
for (int i = 0; i < a.size(); i++) c[i].resize(b[0].size());
for (int i = 0; i < a.size(); i++) for (int j = 0; j < b[0].size(); j++) {
for (int k = 0; k < a[0].size(); k++) {
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
}
}
return c;
}
ll po(ll a, ll b) {
ll c = 1;
while (b) {
if (b % 2) c = c * a % mod;
a = a * a % mod;
b /= 2;
}
return c;
}
int main() {
int t;
cin >> t;
while (t--) {
ll n, k, l, z = 1;
cin >> n >> k >> l;
ll m = (l * l - 3 * l + 3) % mod;
z = po(m, n - 1);
z = po(z, k);
vector<vector<ll>> a = {{0, 1}, {l - 1, l - 2}}, b = {{1, 0}, {0, 1}};
while (k) {
if (k % 2) b = mul(b, a);
a = mul(a, a);
k /= 2;
}
//cout << b[0][0] << ' ' << b[0][1] << ' ' << b[1][0] << ' ' << b[1][1] << '\n';
cout << z * b[0][0] % mod * l % mod << '\n';
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3464kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3416kb
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