比赛 4043级NOIP2022欢乐赛1st 评测结果 MMMMMMMMMM
题目名称 Multiplayer Moo 最终得分 0
用户昵称 HeSn 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2022-10-28 21:21:46
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 50000010;
int n, m, p, a[MAXN], b[MAXN], cnt;
map<int, int> mp;
signed main() {
	freopen("nummaze.in", "r", stdin);
	freopen("nummaze.out", "w", stdout);
	cin >> n >> m >> p;
	a[1] = 1;
	a[2] = 2;
	for(int i = 3; i; i ++) {
		a[i] = a[i - 1] + a[i - 2];
		cnt = i;
		if(a[i] * 2 >= n) {
			break;
		}
	}
	b[1] = 3;
	b[2] = 5;
	for(int i = 3; i <= cnt; i ++) {
		b[i] = b[i - 1] + b[i - 2];
	}
	int x = 1, w = n - 1;
	for(int i = cnt; i >= 1; i --) {
		while(w >= a[i]) {
			w -= a[i];
			x += b[i];
		}
	}
	a[1] = x;
	a[2] = a[1] * 2 - (n - 1);
	for(int i = 3; i <= n; i ++) {
		a[i] = a[i - 1] + a[i - 2];
		a[i] %= p;
	}
	cout << a[m] % p << endl;
	return 0;
}