2020牛客暑期多校训练营(第一场)J题 Easy Integration

题目链接

https://ac.nowcoder.com/acm/contest/5666/J

题面

2020牛客暑期多校训练营(第一场)J题 Easy Integration_第1张图片

题意

对于给定 n ( n ≤ 1 0 6 ) n(n\leq10^6) n(n106) ∫ 0 1 ( x − x 2 ) n d x \int_{0}^{1}\left(x-x^{2}\right)^{n} \mathrm{d} x 01(xx2)ndx,答案取 m o d , m o d = 998244353 mod,mod=998244353 mod,mod=998244353

思路

首先题目说答案一定是一个分数,并给定了 m o d mod mod,显然要用到逆元

刚开始想着求原函数,结果很傻发现求不出来,求着求着发现和二项展开类似,结果回去反推样例,发现样例1,2,3分别对应的是1/6,1/30,1/140,然后提出一个系数 1 n + 1 \frac{1}{n+1} n+11,发现1/3,1/10,1/35正好满足$ \quad C_{2 n+1}^{n+1} , 然 后 g e t 答 案 就 是 ,然后get答案就是 ,get\frac{1}{(n+1) \cdot C_{2 n+1}^{n+1}}$

下面给出赛后直接推积分的过程:

∫ 0 1 ( x − x 2 ) n d x = ∫ 0 1 x n ( 1 − x ) n d x \int_{0}^{1}\left(x-x^{2}\right)^{n} d x=\int_{0}^{1} x^{n}(1-x)^{n} d x 01(xx2)ndx=01xn(1x)ndx

= 1 n + 1 ∫ 0 1 ( x n + 1 ) ′ ( 1 − x ) n d x =\frac{1}{n+1} \int_{0}^{1}\left(x^{n+1}\right)^{\prime}(1-x)^{n} d x =n+1101(xn+1)(1x)ndx

= x n + 1 ⋅ ( 1 − x ) n ∣ 0 1 − ∫ 0 1 x n + 1 [ ( 1 − x ) n ] ′ d x =\left.x^{n+1} \cdot(1-x)^{n}\right|_{0} ^{1}-\int_{0}^{1} x^{n+1}\left[(1-x)^{n}\right]^{\prime} d x =xn+1(1x)n0101xn+1[(1x)n]dx

= n ∫ 0 1 x n + 1 ( 1 − x ) n − 1 d x n + 1 =\frac{n \int_{0}^{1} x^{n+1}(1-x)^{n-1} d x}{n+1} =n+1n01xn+1(1x)n1dx

依次类推 ⋯ \cdots
= n ⋅ ( n − 1 ) ⋯ 1 ⋅ ∫ 0 1 x 2 n d x ( n + 1 ) ⋅ ( n + 2 ) ⋯ 2 n =\frac{n\cdot(n-1) \cdots 1\cdot \int_{0}^{1} x^{2 n} d x}{(n+1) \cdot(n+2) \cdots 2 n} =(n+1)(n+2)2nn(n1)101x2ndx

= n ! ( n + 1 ) ⋯ ( 2 n + 1 ) =\frac{n !}{(n+1) \cdots(2 n+1)} =(n+1)(2n+1)n!

上下同时乘 n ! n! n!得: ( n ! ) 2 ( 2 n + 1 ) ! \frac{(n!)^{2}}{(2 n+1) !} (2n+1)!(n!)2

∵ C 2 n + 1 n + 1 = ( 2 n + 1 ) ! ( n + 1 ) ! n ! \because \quad C_{2 n+1}^{n+1}=\frac{(2 n+1) !}{(n+1) ! n !} C2n+1n+1=(n+1)!n!(2n+1)!

∴ \therefore 原式 = 1 ( n + 1 ) ⋅ C 2 n + 1 n + 1 =\frac{1}{(n+1) \cdot C_{2 n+1}^{n+1}} =(n+1)C2n+1n+11

得到了原式的分式就很简单了,直接输出其逆元,因为有组合数,且 n n n 1 e 6 1e6 1e6,所以用阶乘取模 O ( n ) O(n) O(n)递推组合数即可。

参考代码

#include 
using namespace std;
typedef long long LL;
const int M = 2e6 + 10;
const int mod = 998244353;
LL fac[M];
LL pow_mod(LL a, LL b) {
  LL ans = 1;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
LL inv(LL a) { return pow_mod(a, mod - 2); }
void init() {
  LL p = mod;
  fac[1] = 1;
  for (int i = 2; i <= M; i++) {
    fac[i] = fac[i - 1] * i % p;
  }
}
LL C(LL n, LL m) {
  return fac[m] * pow_mod(fac[n], mod - 2) % mod * pow_mod(fac[m - n], mod - 2) % mod;
}
void solve() {
  LL n;
  init();
  while (~scanf("%lld", &n)) {
    LL ans = 1;
    ans = (n+1) * C(n + 1, n * 2 + 1) % mod;
    printf("%lld\n", inv(ans));
  }
}
signed main() {
  solve();
  return 0;
}

你可能感兴趣的:(ACM,#,牛客,数学)