编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#20779 | #1029. 寒域爷的兔子 | Accepted | 100 | 243 ms | 388 K | C++ / 960 B | RBQRBQ | 2019-08-02 15:12:14 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define int ll
ll mod;
struct matrix {
ll s[2][2];
int n, m;
void clear() {
s[0][0] = 1;
s[0][1] = 1;
s[1][0] = 1;
s[1][1] = 0;
n = 2;
m = 2;
}
};
matrix mix(matrix A, matrix B) {
matrix re;
re.n = A.n;
re.m = B.m;
for (int i = 0; i < re.n; i++) {
for (int j = 0; j < re.m; j++) {
re.s[i][j] = 0;
for (int k = 0; k < A.m; k++) {
re.s[i][j] = (re.s[i][j] + (A.s[i][k] * B.s[k][j]) % mod) % mod;
}
}
}
return re;
}
matrix qpow(matrix A, ll b) {
matrix re;
re.n = 2;
re.m = 2;
re.s[0][0] = 1;
re.s[0][1] = 0;
re.s[1][0] = 0;
re.s[1][1] = 1;
while (b) {
if (b & 1)
re = mix(re, A);
A = mix(A, A);
b >>= 1;
}
return re;
}
signed main() {
ll n, m;
cin >> n >> mod;
if (n == 1 || n == 2) {
puts("2");
return 0;
}
matrix p, A;
p.s[0][0] = 2;
p.s[1][0] = 2;
p.n = 1;
p.m = 1;
A.clear();
A = qpow(A, n - 2);
p = mix(A, p);
printf("%d", p.s[0][0]);
return 0;
}
用户输出
5770
系统信息
Exited with return code 0
用户输出
27662
系统信息
Exited with return code 0
用户输出
8791
系统信息
Exited with return code 0
用户输出
6732
系统信息
Exited with return code 0
用户输出
1454
系统信息
Exited with return code 0
用户输出
3790
系统信息
Exited with return code 0
用户输出
11690
系统信息
Exited with return code 0
用户输出
2151
系统信息
Exited with return code 0
用户输出
1617
系统信息
Exited with return code 0
用户输出
10509
系统信息
Exited with return code 0
用户输出
4380
系统信息
Exited with return code 0
用户输出
2560
系统信息
Exited with return code 0
用户输出
1938
系统信息
Exited with return code 0
用户输出
10705
系统信息
Exited with return code 0
用户输出
9350
系统信息
Exited with return code 0
用户输出
8076
系统信息
Exited with return code 0
用户输出
7210
系统信息
Exited with return code 0
用户输出
666
系统信息
Exited with return code 0
用户输出
16089
系统信息
Exited with return code 0
用户输出
5065
系统信息
Exited with return code 0
用户输出
9362
系统信息
Exited with return code 0
用户输出
9370
系统信息
Exited with return code 0
用户输出
4198
系统信息
Exited with return code 0
用户输出
4041
系统信息
Exited with return code 0
用户输出
4361
系统信息
Exited with return code 0
用户输出
11702
系统信息
Exited with return code 0
用户输出
13980
系统信息
Exited with return code 0
用户输出
1442
系统信息
Exited with return code 0
用户输出
24628
系统信息
Exited with return code 0
用户输出
6954
系统信息
Exited with return code 0
用户输出
5562
系统信息
Exited with return code 0