logo AlgoBeat OnlineJudge
登录 注册

Official Editorial

作者: 035966_L3  ·  发布于 2026-06-14 21:50:57  ·  最后修改于 2026-06-15 16:52:44
已通过
审核员:Lightning ING · 2026-06-15 16:52:44

https://scg3.piaoztsdy.cn/p/158

设取模前的答案为

打表可知,当 时,

根据以上性质,我们直接对 的情况按照 暴力计算即可。

(实际上,这一性质是可以严格证明的,过程如下:)

#include <bits/stdc++.h>
using namespace std;
const int P = 1e8 + 7;
int read()
{
	int x = 0;
	char c = getchar_unlocked();
	while (c < '0') c = getchar_unlocked();
	while (c >= '0')
	{
		x = x * 10 + c - '0';
		c = getchar_unlocked();
		x = min(x, 1000);
	}
	return x;
}
int divs(int a, int b, int p = P)
{
	if (b % a == 0) return b / a;
	int x = divs(p % a, a - b % a, a);
	return (1ll * x * p + b) / a;
}
long long calc(long long x, long long y)
{
	return divs((833 + x * y) % P, (y * y + 2023 * x) % P);
}
signed main()
{
	freopen("calc.in", "r", stdin);
	freopen("calc.out", "w", stdout);
	int T = read();
	while (T--)
	{
		int n = read();
		int res = n;
		for (int i = n - 1; i >= 1; i--)
			res = calc(res, i);
		cout << res << endl;
	}
	return 0;
}

暂无评论

登录 后即可评论。