编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#22803 | #1029. 寒域爷的兔子 | Accepted | 100 | 136 ms | 360 K | C++ / 1.4 K | 机类910-尚锦奥 | 2020-02-14 20:45:03 |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#define lson node << 1
#define rson node << 1 | 1
using namespace std;
#define ll unsigned long long
const ll maxn = 5e5 + 10;
ll read() {
char c = getchar();
ll x = 0;
ll flag = 1;
while (c < '0' || c > '9') {
if (c == '-')
flag = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - 48;
c = getchar();
}
x *= flag;
return x;
}
struct node {
ll p[4][4];
};
ll n, mod;
node cheng(node x, node y, int a, int b, int c) {
node d;
memset(&d, 0, sizeof(node));
for (int i = 1; i <= a; i++) {
for (int j = 1; j <= c; j++) {
for (int k = 1; k <= b; k++) {
(d.p[i][j] += x.p[i][k] % mod * y.p[k][j] % mod) %= mod;
}
}
}
return d;
}
node pow4(node a, ll b) {
b -= 1;
node base = a, r;
memset(r.p, 0, sizeof(r.p));
for (int i = 1; i <= 3; i++) r.p[i][i] = 1;
while (b > 0) {
if (b & 1LL)
r = cheng(r, base, 3, 3, 3);
base = cheng(base, base, 3, 3, 3);
b >>= 1LL;
}
return r;
}
int main() {
n = read(), mod = read();
node a, b, c;
memset(&a, 0, sizeof(node));
memset(&b, 0, sizeof(node));
memset(&c, 0, sizeof(node));
a.p[1][1] = 2;
a.p[2][1] = 2;
a.p[3][1] = 0;
b.p[1][1] = 1;
b.p[1][2] = 1;
b.p[2][1] = 1;
b.p[3][2] = 1;
c = pow4(b, n);
a = cheng(c, a, 3, 3, 1);
printf("%lld", (a.p[2][1] + 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