编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#100282 | #1029. 寒域爷的兔子 | Accepted | 100 | 279 ms | 464 K | C++ 17 (Clang) / 832 B | Dytchem | 2023-07-11 18:15:30 |
#include <iostream>
using namespace std;
typedef unsigned long long ll;
ll k;
struct mat {
ll a11, a12, a21, a22;
};
void sq(mat &m) {
ll a11 = m.a11;
ll a12 = m.a12;
ll a21 = m.a21;
ll a22 = m.a22;
m.a11 = (a11 * a11 + a12 * a21) % k;
m.a12 = (a11 * a12 + a12 * a22) % k;
m.a21 = (a21 * a11 + a22 * a21) % k;
m.a22 = (a21 * a12 + a22 * a22) % k;
}
int main() {
ll m;
cin >> m >> k;
if (m == 1 || m == 2) {
cout << 2 % k;
return 0;
}
m -= 2;
// cout << m << endl;
mat a;
a.a11 = a.a12 = a.a21 = 1;
a.a22 = 0;
ll a1 = 2, a2 = 2;
for (ll i = 0; m != 0; ++i) {
ll t1 = a1, t2 = a2;
if (m & 1) {
a1 = (a.a11 * t1 + a.a12 * t2) % k;
a2 = (a.a21 * t1 + a.a22 * t2) % k;
}
sq(a);
m >>= 1;
// cout << a1 << ' ';
}
cout << a1;
}
用户输出
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