QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#798665#9553. The HermitPepinotWA 12ms5548kbC++231.8kb2024-12-04 15:52:352024-12-04 15:52:35

Judging History

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

  • [2024-12-04 15:52:35]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:5548kb
  • [2024-12-04 15:52:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>

const int mod=998244353;
const int N=1e5+5;

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

void pre(){
    fac[0]=infac[0]=1;
    for(int i=1;i<=1e5;i++)
    {
        fac[i]=fac[i-1]*i%mod;
        infac[i]=infac[i - 1] * quick_pow(i,mod-2,mod)%mod;
    }
}

int cc(int a,int b){
    return fac[a] * infac[b] % mod * infac[a - b] % mod;
}

auto power (int x, int p, int mod) {
    int res = 1;
    while (p) {
        if (p & 1) {
            res = res * x % mod;
        }
        x = x * x % mod;
        p >>= 1;
    }
    return res;
}

void solve() {
    int m,n; cin>>m>>n;

    int a=m/n,b=m/(n-1);
    int x,y;
    for(int i=1; ;i++) {
        if(pow(i,n)>m) {
            x=i-1;
            break;
        }
    }
    for(int i=1; ;i++) {
        if(pow(i,n-1)>m) {
            y=i-1;
            break;
        }
    }
    // cout<<a<<" "<<b<<endl;
    // cout<<x<<" "<<y<<endl;
    int ans=(cc(m,n)*n-cc(m-1,n-1))%mod;
    // cout<<ans<<endl;
    for(int i=2; i<=a; i++) {
        int cnt1=m/i;
        int cnt2=cc(cnt1-1,n-1);
        if(i<=x) {
            cnt2=cnt2-1+n;
        }
        ans-=cnt2;
    }

    for(int i=2; i<=b; i++) {
        int cnt1=m/i;
        int cnt2=cc(cnt1-1,n-2);
        if(i<=y) {
            cnt2=cnt2-1+n-1;
        }
        ans-=cnt2;
    }

    cout<<ans<<endl;
}

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

    pre();
    // int t; cin>>t;
    // while(t--)
    // cout<<cc(100000,99999)<<endl;
        solve();
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 5544kb

input:

4 3

output:

7

result:

ok 1 number(s): "7"

Test #2:

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

input:

11 4

output:

1187

result:

ok 1 number(s): "1187"

Test #3:

score: 0
Accepted
time: 12ms
memory: 5544kb

input:

100000 99999

output:

17356471

result:

ok 1 number(s): "17356471"

Test #4:

score: -100
Wrong Answer
time: 8ms
memory: 5512kb

input:

11451 1919

output:

-2508552614

result:

wrong answer 1st numbers differ - expected: '845616153', found: '-2508552614'