编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#55660 | #1029. 寒域爷的兔子 | Accepted | 100 | 129 ms | 376 K | C++ / 1.3 K | q3540555 | 2021-07-09 23:13:26 |
#include <iostream>
using namespace std;
unsigned long long int M, K;
struct FibMatrix {
FibMatrix() {
fibmat[0][0] = fibmat[0][1] = fibmat[1][0] = 1;
fibmat[1][1] = 0;
}
public:
unsigned long long int fibmat[2][2];
};
FibMatrix multiple(FibMatrix a, FibMatrix b) {
FibMatrix m;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
m.fibmat[i][j] = 0;
for (int k = 0; k < 2; ++k) {
m.fibmat[i][j] += ((a.fibmat[i][k] % K) * (b.fibmat[k][j] % K)) % K;
m.fibmat[i][j] %= K;
}
}
}
return m;
}
FibMatrix power(const FibMatrix& m, unsigned long long int exp) // n次方
{
if (exp == 0) {
FibMatrix r;
r.fibmat[0][0] = r.fibmat[1][1] = 1;
r.fibmat[0][1] = r.fibmat[1][0] = 0;
return r;
}
FibMatrix value = power(m, exp / 2);
if (exp % 2)
return multiple(m, multiple(value, value));
else
return multiple(value, value);
}
unsigned long long int fibonacci(unsigned long long int n) {
FibMatrix m;
m = power(m, n);
return m.fibmat[0][1];
}
int main() {
cin >> M >> K;
unsigned long long int res;
res = ((2 % K) * (fibonacci(M) % K)) % K;
cout << res;
}
用户输出
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