QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#762740 | #9553. The Hermit | wsxcb# | WA | 141ms | 24748kb | C++17 | 1.4kb | 2024-11-19 16:27:44 | 2024-11-19 16:27:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define se second
#define fi first
const int N=1e5+5,mod=998244353;
//#define int long long
int ans=0;
ll fac[N],invfac[N];
ll ksm(ll a,ll b){
ll ans=1;
while(b){
if(b&1)ans=ans*a%mod;
a=a*a%mod;b/=2;
}
return ans%mod;
}
ll C(int x,int y){
if(x<y)return 0;
return fac[x]*invfac[y]%mod*invfac[x-y]%mod;
}
int m,n;
ll dp[N][25];
void add(ll &x,ll y){
x+=y;
if(x>=mod)x-=mod;
}
ll get(ll x,ll y){
ll ans=C(x,y);
if(y>x)return 0;
for(int i=2;i<=x+1;i++){
int c=(x+1)/i-1;
ans=(ans-C(c,y-1));
if(ans<0)ans+=mod;
}
return ans%mod;
}
void solve(){
cin>>m>>n;
fac[0]=1;
for(int i=1;i<=m;i++)fac[i]=fac[i-1]*i%mod;
invfac[m]=ksm(fac[m],mod-2);
for(int i=m-1;i>=0;i--)
invfac[i]=invfac[i+1]*(i+1)%mod;
ans=1ll*C(m,n)*n%mod;
//cout<<ans<<'\n';
ll res=0;
for(int i=1;i<=m;i++){
dp[i][1]++;
for(int j=i+i;j<=m;j+=i){
for(int k=1;k<20;k++){
add(dp[j][k+1],dp[i][k]);
}
}
}
//cout<<get(2,2)<<'\n';
for(int i=1;i<=20;i++){
for(int j=1;j<=m;j++){
int x=m/j-1;
ll g=dp[j][i]*get(x,n-i)%mod*i%mod;
ans-=g;
//cout<<ans<<'\n';
if(ans<0)ans+=mod;
}
}
cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5648kb
input:
4 3
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5768kb
input:
11 4
output:
1187
result:
ok 1 number(s): "1187"
Test #3:
score: 0
Accepted
time: 56ms
memory: 24748kb
input:
100000 99999
output:
17356471
result:
ok 1 number(s): "17356471"
Test #4:
score: 0
Accepted
time: 3ms
memory: 8032kb
input:
11451 1919
output:
845616153
result:
ok 1 number(s): "845616153"
Test #5:
score: 0
Accepted
time: 61ms
memory: 24728kb
input:
99998 12345
output:
936396560
result:
ok 1 number(s): "936396560"
Test #6:
score: -100
Wrong Answer
time: 141ms
memory: 24692kb
input:
100000 1
output:
776108950
result:
wrong answer 1st numbers differ - expected: '0', found: '776108950'