QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#778590#9553. The HermitaYi_7#WA 88ms5916kbC++231.7kb2024-11-24 15:21:172024-11-24 15:21:18

Judging History

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

  • [2024-11-24 15:21:18]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:5916kb
  • [2024-11-24 15:21:17]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
using namespace std;
const int mod = 998244353;
const int N = 1e5 + 7;
int fac[N], inv[N];
int fc[N];

int qmi(int a, int b) {
    a %= mod;
    int res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = inv[0] = fac[1] = inv[1] = 1;
    for (int i = 2; i < N; i++) fac[i] = i * fac[i - 1] % mod;
    inv[N - 1] = qmi(fac[N - 1], mod - 2ll);
    for (int i = N - 2; i > 1; i--) inv[i] = (int)(i + 1) * inv[i + 1] % mod;
    for(int i=1;i<N;i++)
        for(int j=i+i;j<N;j+=i)
            fc[j]++;
}

//int A(int a,int b){return fac[a]*inv[a-b]%mod;}
int C(int a, int b) {
    if(b==0||b==a)return 1;
    if(b>a)return 0;
    return fac[a] * inv[a - b] % mod * inv[b] % mod;
}

void solve() {
    int m,n;
    cin>>m>>n;
    int ans=n*C(m,n)%mod;
    //cout<<ans<<"\n";
    for(int i=1;i<=m;i++){
        int b=m/i-1ll;
        map<int,int>hh;
        int id=i;
        for(int j=2;j*j<=i;j++)
            while(id%j==0){
                id/=j;
                hh[j]++;
            }
        if(id>1)hh[id]++;
        vector<int>h;
        int s=0;
        for(auto &[k,j]:hh)h.emplace_back(j),s+=j;
        for(int j=1;j<=min(20ll,n);j++){
            int sub=C(s,j-1)*fac[s]%mod;
            for(int &k:h)sub=sub*inv[k]%mod;
            sub= sub * C(b,n-j) %mod;
            ans=(ans+mod-sub)%mod;
        }
    }
    cout<<ans<<"\n";
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    init();

    int t = 1;
    // std::cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5872kb

input:

4 3

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 3ms
memory: 5916kb

input:

11 4

output:

1187

result:

ok 1 number(s): "1187"

Test #3:

score: 0
Accepted
time: 88ms
memory: 5912kb

input:

100000 99999

output:

17356471

result:

ok 1 number(s): "17356471"

Test #4:

score: 0
Accepted
time: 8ms
memory: 5912kb

input:

11451 1919

output:

845616153

result:

ok 1 number(s): "845616153"

Test #5:

score: -100
Wrong Answer
time: 88ms
memory: 5872kb

input:

99998 12345

output:

42538319

result:

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