QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#769077 | #9553. The Hermit | Suhy# | TL | 625ms | 23608kb | C++17 | 1.9kb | 2024-11-21 16:01:43 | 2024-11-21 16:01:45 |
Judging History
answer
#include<bits/stdc++.h>
#pragma GCC optimize(3)
typedef unsigned long long u64;
const int M=998244353;
int n,m,i,j,k;
int s,p[10086],l[100086],D[100086];
bool b[100086];
u64 F[100086],G[100086];
u64 *f[100086],*g[100086];
int d[100086];
u64 ans;
u64 pow(u64 u,u64 d){
if(!u)return 1;
u64 r=pow(u>>1,d);
r*=r;
if(u&1)(r%=M)*=d;
return r%M;
}
u64 C(int n,int m){
if(n<m)return 0;
return F[n]*G[m]%M*G[n-m]%M;
}
std::vector <int> fac[100086];
int main(){
scanf("%d%d",&n,&m);
if(m==1){
printf("0");
return 0;
}
F[0]=1;
for(i=1;i<=n;++i)F[i]=F[i-1]*i%M;
G[n]=pow(M-2,F[n]);
for(i=n;i;--i)G[i-1]=G[i]*i%M;
for(i=2;i<=n;++i){
if(!b[i])p[s++]=i,l[i]=i,D[i]=2;
for(j=0;j<s&&p[j]<=i&&(k=i*p[j],k<=n);++j)
b[k]=1,l[k]=p[j],D[k]=D[i]+1;
}
for(int i = 1; i <= n; i ++)
for(int j = i+i; j <= n; j += i)
fac[j].push_back(i);
if(m==2){
ans=(u64)n*(n-1);
for(i=1;i<=n;++i)ans-=fac[i].size()*2;
printf("%llu",ans%M);
return 0;
}
D[1]=1;
for(i=1;i<=n;++i){
g[i]=new u64[D[i]+1];
for(j=0;j<D[i];++j)g[i][j+1]=0;
g[i][0]=1;
for(int j : fac[i]){
for(k=0;k<=D[j];++k)(g[i][k+1]+=g[j][k])%=M;
}
}
for(i=1;i<=n;++i)if(d[n/i]<D[i])d[n/i]=D[i];
for(i=n;i;--i)
for(k=2;k<=i&&i/k>=m-d[i];++k)
if(d[i/k]<d[i])d[i/k]=d[i];
for(i=1;i<=n;++i)if(d[i]){
f[i]=new u64[d[i]+1];
for(j=0;j<=d[i]&&j<m;++j){
f[i][j]=C(i,m-j);
for(k=2;k<=i&&i/k>=m-j;++k)
(f[i][j]+=M-f[i/k][j])%=M;
}
}
for(i=1;i<=n;++i)
for(j=0;j<=D[i]&&j<m;++j){
u64 u=f[n/i][j]+C(n/i-1,m-j)+M-C(n/i,m-j);
ans+=g[i][j]*u%M*(m-j)%M;
if(j)ans+=g[i][j-1]*u%M*(m-j)%M;
}
printf("%llu",ans%M);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8980kb
input:
4 3
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9456kb
input:
11 4
output:
1187
result:
ok 1 number(s): "1187"
Test #3:
score: 0
Accepted
time: 48ms
memory: 23492kb
input:
100000 99999
output:
17356471
result:
ok 1 number(s): "17356471"
Test #4:
score: 0
Accepted
time: 6ms
memory: 11384kb
input:
11451 1919
output:
845616153
result:
ok 1 number(s): "845616153"
Test #5:
score: 0
Accepted
time: 52ms
memory: 23568kb
input:
99998 12345
output:
936396560
result:
ok 1 number(s): "936396560"
Test #6:
score: 0
Accepted
time: 1ms
memory: 6448kb
input:
100000 1
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 625ms
memory: 23520kb
input:
100000 15
output:
190067060
result:
ok 1 number(s): "190067060"
Test #8:
score: 0
Accepted
time: 0ms
memory: 8964kb
input:
10 3
output:
299
result:
ok 1 number(s): "299"
Test #9:
score: 0
Accepted
time: 0ms
memory: 9424kb
input:
10 4
output:
743
result:
ok 1 number(s): "743"
Test #10:
score: 0
Accepted
time: 2ms
memory: 9212kb
input:
10 5
output:
1129
result:
ok 1 number(s): "1129"
Test #11:
score: 0
Accepted
time: 0ms
memory: 9396kb
input:
15 6
output:
28006
result:
ok 1 number(s): "28006"
Test #12:
score: 0
Accepted
time: 0ms
memory: 9752kb
input:
15 7
output:
42035
result:
ok 1 number(s): "42035"
Test #13:
score: 0
Accepted
time: 0ms
memory: 9704kb
input:
123 45
output:
214851327
result:
ok 1 number(s): "214851327"
Test #14:
score: 0
Accepted
time: 2ms
memory: 9352kb
input:
998 244
output:
964050559
result:
ok 1 number(s): "964050559"
Test #15:
score: 0
Accepted
time: 2ms
memory: 9724kb
input:
1919 810
output:
379720338
result:
ok 1 number(s): "379720338"
Test #16:
score: 0
Accepted
time: 1ms
memory: 9236kb
input:
1048 576
output:
216543264
result:
ok 1 number(s): "216543264"
Test #17:
score: 0
Accepted
time: 2ms
memory: 8852kb
input:
999 777
output:
635548531
result:
ok 1 number(s): "635548531"
Test #18:
score: 0
Accepted
time: 42ms
memory: 23608kb
input:
99999 77777
output:
448144614
result:
ok 1 number(s): "448144614"
Test #19:
score: 0
Accepted
time: 15ms
memory: 14136kb
input:
34527 6545
output:
748108997
result:
ok 1 number(s): "748108997"
Test #20:
score: 0
Accepted
time: 13ms
memory: 10436kb
input:
12345 12
output:
777496209
result:
ok 1 number(s): "777496209"
Test #21:
score: 0
Accepted
time: 1ms
memory: 6264kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 39ms
memory: 23572kb
input:
100000 10101
output:
855985819
result:
ok 1 number(s): "855985819"
Test #23:
score: 0
Accepted
time: 48ms
memory: 23492kb
input:
100000 91919
output:
92446940
result:
ok 1 number(s): "92446940"
Test #24:
score: 0
Accepted
time: 39ms
memory: 23484kb
input:
100000 77979
output:
106899398
result:
ok 1 number(s): "106899398"
Test #25:
score: 0
Accepted
time: 10ms
memory: 10600kb
input:
10000 11
output:
326411649
result:
ok 1 number(s): "326411649"
Test #26:
score: 0
Accepted
time: 23ms
memory: 18544kb
input:
100000 2
output:
15322970
result:
ok 1 number(s): "15322970"
Test #27:
score: -100
Time Limit Exceeded
input:
100000 3