[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
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
输入格式
The first line contains one integer
The second line contains
Note that two points may be in the same position.
输出格式
Output one integer, the answer modulo
样例 #1
样例输入 #1
3
1 2 4
样例输出 #1
332748120
题解
本题其实就是求
记
所以,仅求
因为
所以
所以
#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;
}