编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#21101 | #1029. 寒域爷的兔子 | Accepted | 100 | 121 ms | 380 K | C++ 17 / 1.4 K | 自动化82-郭筠陶 | 2020-01-15 11:49:03 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int MOD;
class matric2 {
public:
vector<vector<ll> > a;
static const int dimension = 2;
void operator=(matric2 a) {
for (int i = 0; i < dimension; i++) {
for (int j = 0; j < dimension; j++) {
this->a[i][j] = a.a[i][j];
}
}
}
matric2(int a1, int b, int c, int d) {
a = vector<vector<ll> >(dimension, vector<ll>(dimension, 0));
a[0][0] = a1;
a[0][1] = b;
a[1][0] = c;
a[1][1] = d;
}
matric2() { a = vector<vector<ll> >(dimension, vector<ll>(dimension, 0)); }
friend matric2 multiple(matric2 a, matric2 b) {
matric2 c;
for (int i = 0; i < a.dimension; i++) {
for (int j = 0; j < a.dimension; j++) {
c.a[i][j] = 0;
for (int k = 0; k < a.dimension; k++) {
c.a[i][j] += a.a[i][k] * b.a[k][j] % MOD;
c.a[i][j] %= MOD;
}
}
}
return c;
}
};
int main() {
ll month;
cin >> month >> MOD;
matric2 fibMat(1, 1, 1, 0);
matric2 ans(1, 0, 0, 1);
month--;
while (month != 0) {
if (month % 2 == 1)
ans = multiple(ans, fibMat);
fibMat = multiple(fibMat, fibMat);
month /= 2;
}
cout << (ans.a[0][0] * 2 % MOD) % MOD;
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