QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#778610#9553. The HermitaYi_7#WA 252ms5404kbC++231.6kb2024-11-24 15:26:402024-11-24 15:26:40

Judging History

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

  • [2024-11-24 15:26:40]
  • 评测
  • 测评结果:WA
  • 用时:252ms
  • 内存:5404kb
  • [2024-11-24 15:26:40]
  • 提交

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 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;
}

//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;
    for(int i=1;i<=m;i++){
        int b=m/i-1ll;
        map<int,int>hh;
        int id=i,c=0;
        for(int j=2;j*j<=i;j++)
            while(id%j==0){
                id/=j;
                hh[j]++;
                c++;
            }
        if(id>1){
            hh[id]++;
            c++;
        }
        int s=1;
        for(auto &[k,j]:hh)s=s*inv[j]%mod;
        for(int j=1;j<=min(500ll,n);j++){
            int sub=C(c,j-1)*fac[c]%mod;
            sub=sub*s%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;
}

詳細信息

Test #1:

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

input:

4 3

output:

7

result:

ok 1 number(s): "7"

Test #2:

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

input:

11 4

output:

1187

result:

ok 1 number(s): "1187"

Test #3:

score: 0
Accepted
time: 249ms
memory: 5208kb

input:

100000 99999

output:

17356471

result:

ok 1 number(s): "17356471"

Test #4:

score: 0
Accepted
time: 22ms
memory: 5404kb

input:

11451 1919

output:

845616153

result:

ok 1 number(s): "845616153"

Test #5:

score: -100
Wrong Answer
time: 252ms
memory: 5116kb

input:

99998 12345

output:

42538319

result:

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