QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#800885 | #9553. The Hermit | Pepinot | WA | 60ms | 21424kb | C++23 | 1.6kb | 2024-12-06 16:26:17 | 2024-12-06 16:26:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
using pii=pair<int,int>;
const int N=100005,M=100000;
const int mod=998244353;
int n,m;
int f[22][N],cnt[N];
int fac[N],infac[N];
int quick_pow(int a, int k, int p)
{
int res = 1;
while (k)
{
if (k & 1) res = res * a % p;
a = a * a % p;
k >>= 1;
}
return res;
}
int cc(int a,int b){
if(b>a) return 0;
return fac[a] * infac[b] % mod * infac[a - b] % mod;
}
void pre(){
fac[0]=infac[0]=1;
for(int i=1;i<=M;i++)
{
fac[i]=fac[i-1]*i%mod;
infac[i]=infac[i - 1] * quick_pow(i,mod-2,mod)%mod;
}
//求cnt[i]
for(int i=1; i<=M; i++) {
int w=i;
for(int j=2; j<=w/j; j++) {
while(w%j==0) {
w/=j;
cnt[i]++;
}
}
if(w>1) cnt[i]++;
cnt[i]++;
}
cnt[1]=1;
// 求f[i][j]
for(int j=1; j<=M; j++) {
// cout<<j<<":";
for(int i=1; i<=cnt[j]; i++) {
f[i][j]=cc(cnt[j]-1,i-1);
// cout<<f[i][j]<<" \n"[i==cnt[j]+1];
}
}
}
//f[i][j] 表示长度为i,当前数为j的方案数
void solve(){
cin>>m>>n;
int ans=0;
for(int j=1; j<=m; j++) {
for(int i=1; i<=cnt[j]; i++) {
ans+=f[i][j]*cc(m/j-1,n-i);
ans%=mod;
}
}
// cout<<cc(m,n)*n<<" "<<ans<<endl;
cout<<(cc(m,n)*n-ans)%mod;
}
signed main(){
ios::sync_with_stdio(false),cin.tie(nullptr);
pre();
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 51ms
memory: 20364kb
input:
4 3
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 56ms
memory: 20972kb
input:
11 4
output:
1187
result:
ok 1 number(s): "1187"
Test #3:
score: 0
Accepted
time: 60ms
memory: 21424kb
input:
100000 99999
output:
17356471
result:
ok 1 number(s): "17356471"
Test #4:
score: 0
Accepted
time: 55ms
memory: 21000kb
input:
11451 1919
output:
845616153
result:
ok 1 number(s): "845616153"
Test #5:
score: -100
Wrong Answer
time: 56ms
memory: 21192kb
input:
99998 12345
output:
937364469
result:
wrong answer 1st numbers differ - expected: '936396560', found: '937364469'