链接:https://ac.nowcoder.com/acm/contest/5666/J
来源:牛客网
题目描述:
Given n,find the value of
It can be proved that the value is a rational number .
Print the result as ( ) 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≤1e6
The number of test cases does not exceed 1e5
输出描述:
For each test case, print an integer which denotes the result.
solution:
先将函数变成x*(1-x),然后将(1-x)的n次二项式展开,对展开后的函数进行积分,就可以将函数积分出来的公式写出来,然后进行找规律,找出的规律是在前一项上除以一个数,再乘以两个数(具体什么我已经忘了),找规律过程中不要化简,不然找不到规律
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n; const int mod=998244353; ll extend_gcd(ll a,ll b, ll&x,ll &y) { if(a==0&&b==0)return -1; if(b==0){x=1;y=0;return a;} ll d=extend_gcd(b,a%b,y,x); y-=a/b*x; return d; } ll mod_reverse(ll a,ll n) { ll x,y; ll d=extend_gcd(a,n,x,y); if(d==1)return (x%n+n)%n; else return -1; } ll a[2000005]; ll b[2000005]; ll c[2000005]; ll t=4; int main() { a[1]=1; b[1]=6; c[1]=1; for(int i=2;i<=1000000;i++) { a[i]=a[i-1]*i%mod;//cout<<a[i]<<endl; b[i]=b[i-1]*(t*(t+1)%mod)%mod; c[i]=c[i-1]*i%mod; t+=2; } while(~scanf("%d",&n)) { ll s=mod_reverse(b[n],mod)*(a[n]*c[n]%mod)%mod; printf("%lld\n",s); } }