NC209439. EasyIntegration
描述
输入描述
The input consists of several test cases and is terminated by end-of-file.
Each test case contains an integer n.
*
* The number of test cases does not exceed .
输出描述
For each test case, print an integer which denotes the result.
示例1
输入:
1 2 3
输出:
166374059 432572553 591816295
说明:
C++(g++ 7.5.0) 解法, 执行用时: 73ms, 内存消耗: 24812K, 提交时间: 2023-04-29 17:15:53
#include<bits/stdc++.h> using namespace std; #define M 2000010 #define mod 998244353 int n,f[M],g[M],inv[M]; int main() { f[1]=g[1]=inv[1]=1; for(int i=2;i<2000005;i++){ f[i]=1ll*f[i-1]*i%mod; inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod; g[i]=1ll*g[i-1]*inv[i]%mod; } while(~scanf("%d",&n)) printf("%d\n",1ll*g[2*n+1]*f[n]%mod*f[n]%mod); return 0; }
C++(clang++ 11.0.1) 解法, 执行用时: 301ms, 内存消耗: 48736K, 提交时间: 2023-05-04 20:53:53
#include<bits/stdc++.h> using namespace std; const int mod=998244353,mxn=2e6+10;; long long n,f[mxn],g[mxn],a[mxn]; int main(){ f[1]=g[1]=a[1]=1; for(int i=2;i<mxn;i++){ f[i]=f[i-1]*i%mod; a[i]=(mod-mod/i)*a[mod%i]%mod; g[i]=g[i-1]*a[i]%mod; } while(cin>>n) cout<<g[2*n+1]*f[n]%mod*f[n]%mod<<'\n'; return 0; }
pypy3 解法, 执行用时: 554ms, 内存消耗: 41320K, 提交时间: 2023-04-29 13:23:07
Mod = 998244353 fact = [0] * 2000010 fact[0] = 1 for i in range(1, 2000003): fact[i] = i * fact[i - 1] % Mod while True: try: n = int(input()) ans = fact[n] * fact[n] % Mod * pow(fact[2 * n + 1], Mod - 2, Mod) % Mod print(ans) except EOFError: break
Python3(3.5.2) 解法, 执行用时: 1140ms, 内存消耗: 83704K, 提交时间: 2020-07-13 09:49:26
import sys fact = [1] * (2000007) for i in range(1, 2000007): fact[i] = fact[i - 1] * i % 998244353 for line in sys.stdin: sys.stdout.write('%d\n' % (fact[int(line)] ** 2 * pow(fact[2 * int(line) + 1], 998244351, 998244353) % 998244353))