QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#211910 | #6736. Alice and Bob | YFOQ | AC ✓ | 345ms | 163260kb | C++11 | 2.1kb | 2023-10-12 22:50:47 | 2023-10-12 22:50:48 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define endl '\n'
#define fix(x) cout << fixed << setprecision(x) ;
#pragma GCC optimize(2)
using namespace std;
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
typedef pair<int,PII>PIP;
typedef pair<PII,int>PPI;
typedef vector<int>VI;
const int N =5e5+5;
const long long INF = 1e16;
int mod= 998244353;
ll a[10000001];
int kpow(int x,int n);
ll inv[10000001];
vector<int>p;
ll A(int n,int x){
// cout<<n<<" "<<n-x<<endl;
// cout<<a[n]<<" "<<a[n-x]<<endl;
return a[n]*inv[n-x]%mod;
//return a[n]*kpow(a[n-x],mod-2)%mod;
}
inline void Solve(){
int n;
cin>>n;
memset(inv,-1,sizeof inv);
a[0]=1;
inv[1]=1;
inv[0]=1;
a[1]=1;
for(int i=2;i<=n;i++){
if(inv[i]==-1){
p.pb(i);
inv[i]=kpow(i,mod-2);
}
for(auto j:p){
if(j*i>n)break;
inv[i*j]=inv[i]*inv[j]%mod;
if(i%j==0)break;
}
}
for(int i=1;i<=n;i++){
a[i]=a[i-1]*i;
a[i]%=mod;
inv[i]*=inv[i-1];
inv[i]%=mod;
}
// for(int i=1;i<=n;i++){
// cout<<kpow(inv[i],mod-2)<<endl;
// }
ll res =0;
for(int i=1;i<=n/2+1;++i){
res+=A((n-i),i-1)*(a[n-i]);
// cout<<res<<endl;
res%=mod;
}
cout<<res<<endl;
}
//1 0.75
signed main(){
// IO
// fix(16);
int T=1;
// cin>>T;
for(int i=1;i<=T;i++){
Solve();
}
return 0;
}
/*
*/
int lowbit(int n)
{
return n&-n;
}
inline void read(int &x)
{
int f=0;x=0;char c=getchar();
while(c<'0'||c>'9')f|=c=='-',c=getchar();
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
x=f?-x:x;
}
inline void print(long long x)
{
if(x<0){
putchar('-');
x=-x;
}
if(x>9) print(x/10);
putchar(x%10+'0');
}
//ofstream out("file.txt");
//ifstream in("file.txt");
inline int kpow(int x,int y){
if(y==0)return 1;
if(x==0)return 0;
long long res =1;
long long p=x;
for(int i=0;y>>i;++i){
if((y>>i)&1){
res*=p;
res%=mod;
}
p*=p;
p%=mod;
}
return res;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 82656kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 82500kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 82912kb
input:
10
output:
997920
result:
ok 1 number(s): "997920"
Test #4:
score: 0
Accepted
time: 0ms
memory: 83772kb
input:
100
output:
188898954
result:
ok 1 number(s): "188898954"
Test #5:
score: 0
Accepted
time: 7ms
memory: 83564kb
input:
4
output:
10
result:
ok 1 number(s): "10"
Test #6:
score: 0
Accepted
time: 3ms
memory: 83208kb
input:
8
output:
12336
result:
ok 1 number(s): "12336"
Test #7:
score: 0
Accepted
time: 0ms
memory: 82760kb
input:
16
output:
373118483
result:
ok 1 number(s): "373118483"
Test #8:
score: 0
Accepted
time: 0ms
memory: 82004kb
input:
32
output:
314585464
result:
ok 1 number(s): "314585464"
Test #9:
score: 0
Accepted
time: 4ms
memory: 82612kb
input:
64
output:
627827331
result:
ok 1 number(s): "627827331"
Test #10:
score: 0
Accepted
time: 3ms
memory: 83356kb
input:
128
output:
828497685
result:
ok 1 number(s): "828497685"
Test #11:
score: 0
Accepted
time: 0ms
memory: 81876kb
input:
256
output:
65697890
result:
ok 1 number(s): "65697890"
Test #12:
score: 0
Accepted
time: 3ms
memory: 82492kb
input:
512
output:
854187619
result:
ok 1 number(s): "854187619"
Test #13:
score: 0
Accepted
time: 7ms
memory: 83296kb
input:
1024
output:
513823539
result:
ok 1 number(s): "513823539"
Test #14:
score: 0
Accepted
time: 53ms
memory: 93996kb
input:
1361956
output:
617368199
result:
ok 1 number(s): "617368199"
Test #15:
score: 0
Accepted
time: 252ms
memory: 143260kb
input:
7579013
output:
827172636
result:
ok 1 number(s): "827172636"
Test #16:
score: 0
Accepted
time: 290ms
memory: 149812kb
input:
8145517
output:
710624331
result:
ok 1 number(s): "710624331"
Test #17:
score: 0
Accepted
time: 207ms
memory: 131456kb
input:
6140463
output:
707600568
result:
ok 1 number(s): "707600568"
Test #18:
score: 0
Accepted
time: 127ms
memory: 111780kb
input:
3515281
output:
698302413
result:
ok 1 number(s): "698302413"
Test #19:
score: 0
Accepted
time: 251ms
memory: 138592kb
input:
6969586
output:
69470392
result:
ok 1 number(s): "69470392"
Test #20:
score: 0
Accepted
time: 98ms
memory: 105932kb
input:
2888636
output:
433579983
result:
ok 1 number(s): "433579983"
Test #21:
score: 0
Accepted
time: 345ms
memory: 162016kb
input:
9999998
output:
758172780
result:
ok 1 number(s): "758172780"
Test #22:
score: 0
Accepted
time: 345ms
memory: 163260kb
input:
9999999
output:
605195495
result:
ok 1 number(s): "605195495"
Test #23:
score: 0
Accepted
time: 331ms
memory: 162528kb
input:
10000000
output:
866813682
result:
ok 1 number(s): "866813682"