QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185173 | #6736. Alice and Bob | team1041# | TL | 0ms | 0kb | C++20 | 1.2kb | 2023-09-21 18:28:09 | 2023-09-21 18:28:09 |
answer
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);
//#define int long long
#define endl '\n'
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define db double
#define ll long long
using namespace std;
const int N = 1e7+7,mod = 998244353;
ll qmi(ll a, ll b, ll p)
{
ll res = 1;
while(b)
{
if(b & 1) res = (ll)res * a % p;
a = (ll)a * a % p;
b >>= 1;
}
return res;
}
// ll qmi(ll x, ll y, ll p)
// {
// if(y < 0) x = -x, y = -y;
// ll z = (long double)x / p * y;
// ll res = (unsigned long long)x*y - (unsigned long long)z * p;
// return (res + p) % p;
// }
int fa[N],infa[N];
void initcp(int n)
{
fa[0] = infa[0] = 1;
rep(i,1,n-1)
{
fa[i] = (ll)fa[i-1] * i % mod;
infa[i] = (ll)infa[i-1] * qmi(i,mod-2,mod)%mod;
}
}
int P(int a, int b)
{
if(a < b) return 0;
return (ll)fa[a] * infa[a-b] % mod;
}
void solve()
{
int n;
cin >> n;
int ans = 0;
for(int i = 1; i <= n; i ++)
{
ans = (ans + P(n-i,i-1)*fa[n-i]%mod )%mod;
}
cout << ans << endl;
}
signed main()
{
//IOS
int T = 1;
initcp(1e7+6);
//cin >> T;
while(T--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
1
output:
1