【题解】P10329 [UESTCPC 2024] Add

Add

题意

将序列进行一系列的操作,输出对 \(a_{1}\) 的期望值。

题目中操作说的比较明了,再次就不特殊声明了。

思路

据题意所知,每一个 \(n\) 应该对应了一个固定的答案。

于是我就想到可以打表,就打出了下面的式子。

n=1时 ans=1
n=2时 ans=5
n=3时 ans=14
n=4时 ans=30
n=5时 ans=55

我发现这些数不一般,仔细观察后,发现这些数是平方数的和。

\(1^{2}+2^{2}+3^{2}+\dots +n^{2}\)

那么只要计算并化简即可。

答案证明

\(a_{x}\) 代入到 \(a_{y}\) 中得贡献为 \(2x^{2}+2xy\)

则总贡献为 \(1(2x^{2}+2xy)+2(2x^{2}+2xy)+3(2x^{2}+2xy)+\dots+(x-1)(2x^{2}+2xy)=x^{3}-x\)

于是答案为 \(1( \frac{x^{3}-x }{x-1})+2( \frac{x^{3}-x }{x-1})+\dots +x( \frac{x^{3}-x }{x-1})\)

则答案化简后为为 $\frac{n(n+1)(2n+1)}{6} $。

代码

#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
long long t,a,b,n;
int main(){
	cin>>t;
	while(t--){
		cin>>n;
		a=(n*n+n)/2,b=2*n+1;
		if(a%3)b/=3;
		else a/=3;
		cout<<(a%mod)*b%mod<<endl;
	}
	return 0;
}

posted @ 2024-04-27 11:36  Kcjhfqr  阅读(69)  评论(0)    收藏  举报
.poem-wrap { position: relative; width: 1000px; max-width: 80%; border: 2px solid #797979; border-top: none; text-align: center; margin: 40px auto; } .poem-left { left: 0; } .poem-right { right: 0; } .poem-border { position: absolute; height: 2px; width: 27%; background-color: #797979; } .poem-wrap p { width: 70%; margin: auto; line-height: 30px; color: #797979; } .poem-wrap h1 { position: relative; margin-top: -20px; display: inline-block; letter-spacing: 4px; color: #797979; font-size: 2em; margin-bottom: 20px; } #poem_sentence { font-size: 25px; } #poem_info { font-size: 15px; margin: 15px auto; }