跳到正文

个人记录

学生 T3 得 5 分。

TernaryTree约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月26日
篇幅
约 3 分钟

版本

  1. v1当前

CRT,太深刻了。

C++
#include <bits/stdc++.h>
#define int __int128
#define fs first
#define sc second
#define ls (u << 1)
#define rs (u << 1 | 1)
#define mid ((l + r) >> 1)
#define lc ls, l, mid
#define rc rs, mid + 1, r
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
#define gc getchar
#define pc putchar

using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;

const int maxn = 1e6 + 10;
const bool multidata = 0;

int read() {
	int x = 0, f = 1; char c = gc();
	while (c < '0' || c > '9') { if (c == '-') f = -f; c = gc(); }
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc();
	return x * f;
}

void write(int x) {
	if (x < 0) pc('-'), x = -x;
	if (x < 10) return void (pc(x + '0'));
	write(x / 10), pc(x % 10 + '0');
}

vector<pii> Alice(int x) {
	vector<pii> tr;
	rep(i, 2, 5000) tr.push_back({x % (i - 1) + 1, i});
	return tr;
}

vector<pii> Cather(vector<pii> tr) {
	vector<pii> ntr;
	int mx = ((int) tr.size() - 2) / 2;
	srand(time(0)), random_shuffle(tr.begin(), tr.end());
	rep(i, 0, (int) tr.size() - 1 - mx) ntr.push_back(tr[i]);
	return ntr;
}

int Bob(vector<pii> tr) {
	vector<pii> a;
	for (pii e : tr) a.push_back({e.fs - 1, e.sc - 1});
	int cur = a[0].fs, k = 1;
	rep(i, 0, (int) a.size() - 2) {
		k = k / __gcd(k, a[i].sc) * a[i].sc;
		while (cur % a[i + 1].sc != a[i + 1].fs) cur += k;
		if (k > 1e18) break;
	}
	return cur;
}

void fake_main() {
	while (true) write(Bob(Cather(Alice(read())))), pc('\n');
}

signed main() {
	int T = multidata ? read() : 1;
	while (T--) fake_main();
	return 0;
}

原文