[HBCPC2024] Points on the Number Axis A

[HBCPC2024] Points on the Number Axis A

题目描述

Alice is playing a single-player game on the number axis.

There are n points on the number axis. Each time, the player selects two points. The two points will be removed, and their midpoint will be added. When there is only one point on the axis, the game ends. Formally, if the two chosen points is xi and xj, then xi+xj2 will be added after the operation.

In order to play this game happily, Alice will always select two points randomly.

Now Alice have a question: where is the expected position of the last point.

It can be proven that the answer can be expressed in the form pq, you only need to output the value of pq1mod998244353.

输入格式

The first line contains one integer n (1n106).

The second line contains n integers xi (0x1xn<998244353), denoting the position of the i-th point.

Note that two points may be in the same position.

输出格式

Output one integer, the answer modulo 998244353.

样例 #1

样例输入 #1

3
1 2 4

样例输出 #1

332748120

题解

本题其实就是求i=xnxin

S=i=xnxim=998244353an 在模 m 下的逆元;

所以,仅求(S×a)%m

因为 an1(mod m)

所以 annm1(mod m)(根据 费马小定理 ap11(mod p));

所以 amm2(mod m)

#include <iostream>

using namespace std;
 	`	1	1	1	1	1	1	1`
const int mod = 998244353;

//快速幂求逆元
long long qpow(int a, int b) {
	long long ans = 1;
	while (b) {
		if (b & 1)ans = ans * a % mod;

		a = (1ll * a * a) % mod;// 可能溢出,用long long防止 // 由于%的优先度高于*,所以先计算1ll*a*a再取模

		b >>= 1;

	}
	return ans;
}


int main()
{
	int n; cin >> n;

	long long sum = 0, x;
	for (int i = 0; i < n; i++)cin >> x, sum = (sum + x) % mod;

	cout << sum * qpow(n, mod - 2) % mod << endl;

	return 0;
}
posted @   风掣凧浮  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
点击右上角即可分享
微信分享提示