Easy Integration
题目大意
Given n, find the value of
∫
0
1
(
x
−
x
2
)
n
d
x
\int_{0}^1 (x - x^2)^n \mathrm{d} x
∫01(x−x2)ndx∫
It can be proved that the value is a rational number
p
q
\frac{p}{q}
qp.
Print the result as (
p
⋅
q
−
1
)
m
o
d
p \cdot q^{-1}) \bmod
p⋅q−1)mod 998244353.
输入描述:
The input consists of several test cases and is terminated by end-of-file.
Each test case contains an integer n.
- 1 ≤ n ≤ 1 0 6 \leq n \leq 10^6 ≤n≤106
- The number of test cases does not exceed 10 5 ^5 5
输出描述:
For each test case, print an integer which denotes the result.
输入样例
1
2
3
输出样例
166374059
432572553
591816295
For n = 1,
∫
0
1
(
x
−
x
2
)
d
x
=
x
2
2
−
x
3
3
∣
0
1
\int_{0}^1 (x - x^2) \mathrm{d} x = \frac{x^2}{2} - \frac{x^3}{3} |_0^1
∫01(x−x2)dx=2x2−3x3∣01 =
1
6
\frac{1}{6}
61
求一下逆元
X=166374059,a=1,b=6;
a/b mod 998244353==X
a mod 998244353 == b*X mod 998244353
oeis
#include <cstdio>
#include <algorithm>
#define rep(i,a,b) for(auto i=a;i<=b;++i)
using namespace std;
typedef long long ll;
const int mod=998244353,maxn=1e6+7;
ll a[maxn<<1],b[maxn<<1],inv[maxn<<1];
int main()
{
int n;
a[0]=b[0]=b[1]=inv[1]=inv[0]=1;
rep(i,1,maxn<<1){
a[i]=a[i-1]*i%mod;
if(i>1) inv[i]=(mod-mod/i)*inv[mod%i]%mod,b[i]=b[i-1]*inv[i]%mod;
}
while(~scanf("%d",&n))
printf("%lld\n",((a[n]%mod*a[n]%mod*b[(n<<1)+1]%mod)+mod)%mod);
return 0;
}