QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408247 | #6736. Alice and Bob | TANGTANGCC | TL | 0ms | 0kb | C++23 | 927b | 2024-05-09 21:46:13 | 2024-05-09 21:46:15 |
answer
#include <bits/stdc++.h>
#include <sstream>
#define int long long
#define endl '\n'
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
using namespace std;
const int MOD=998244353,N=1e7+50;
int fact[N],inv[N],fain[N];
int qmi(int a,int n) {
int ans=1;
while(n) {
if(n&1) ans=(ans*a)%MOD;
a=a*a%MOD;
n>>=1;
}
return ans;
}
void init() {
fact[0]=fact[1]=inv[0]=inv[1]=fain[0]=fain[1]=1;
for (int i = 2; i <= 1e7+5; ++i) {
fact[i]=(fact[i-1]*i)%MOD;
inv[i]=qmi(i,MOD-2)%MOD;
fain[i]=fain[i-1]*inv[i]%MOD;
}
}
int A(int n,int m) {
return fact[n]*fain[n-m]%MOD;
}
signed main() {
IO;
int n,ans=0;
cin>>n;
init();
for (int i = 1; i <= n; ++i) {
if(n-i<i-1) break;
ans=(ans+A(n-i,i-1)*fact[n-i]%MOD)%MOD;
}
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
1