QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#790017#9553. The Hermitxiaozong85WA 13ms10808kbC++141.8kb2024-11-27 23:37:232024-11-27 23:37:26

Judging History

你现在查看的是最新测评结果

  • [2024-11-27 23:37:26]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:10808kb
  • [2024-11-27 23:37:23]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define rep_(i, l, r) for (int i = l; i >= r; i--)
#define cy cout << "YES" << '\n'
#define cn cout << "NO" << '\n'
#define xx first
#define yy second
#define pb push_back
#define endl '\n'
const int N=1e5+10;
const int mod=998244353;
//#define int ll
using namespace std;
int T=1;
int dp[20][N];//长度为c,以x结尾的方案数
int n,m;
int addv(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
int subv(int x,int y){return (x>=y)?(x-y):(x-y+mod);}
void add(int& x,int y){x = addv(x,y);}
void sub(int& x,int y){x = subv(x,y);}
int qpow(int a,int n){
    int res = 1; a%=mod;
    while(n){
        if(n&1)res = 1ll*res*a%mod;
        n>>=1; a = 1ll*a*a%mod;
    }
    return res;
}
int qinv(int a){return qpow(a,mod-2);}
//
ll fac[N],rfac[N],ans;

int C(int n,int m){
    if(n<m || m<0)return 0;
    return 1ll*fac[n]*rfac[m]%mod*rfac[n-m]%mod;
}

void solve(){
	cin>>m>>n;
	//cout<<dp[4][8]<<endl;
	fac[0] = 1; for(int i=1;i<=m;i++)fac[i] = 1ll*fac[i-1]*i%mod;
    rfac[m] = qinv(fac[m]); for(int i=m-1;i>=0;i--)rfac[i] = 1ll*rfac[i+1]*(i+1)%mod;
	rep(i,1,m)dp[1][i]=1;
	rep(i,1,m){
		for(int j=1;j<20;j++){
			if(dp[j][i]){
				int w=dp[j][i];
				for(int k=2*i;k<=m;k+=i){
					dp[j+1][k]+=w;
				}
			}
		}
	}
	ans=1ll*C(m,n)*n%mod;
	for(int j=1;j<=m;j++){
		for(int i=1;i<20&&i<=n;i++){
			if(dp[i][j]){
				if(m/j<1)continue;
				ans=(ans-(dp[i][j]*C(m/j-1,n-i)%mod))%mod;
				//cout<<i<<" "<<j<<" "<<dp[i][j]<<" "<<ans<<endl;
			}
		}
	}
	cout<<(ans+mod)%mod<<endl;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5632kb

input:

4 3

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5696kb

input:

11 4

output:

1187

result:

ok 1 number(s): "1187"

Test #3:

score: 0
Accepted
time: 13ms
memory: 10568kb

input:

100000 99999

output:

17356471

result:

ok 1 number(s): "17356471"

Test #4:

score: 0
Accepted
time: 2ms
memory: 6216kb

input:

11451 1919

output:

845616153

result:

ok 1 number(s): "845616153"

Test #5:

score: -100
Wrong Answer
time: 6ms
memory: 10808kb

input:

99998 12345

output:

542131975

result:

wrong answer 1st numbers differ - expected: '936396560', found: '542131975'