QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#769880#9553. The HermithxsjWA 39ms5272kbC++143.8kb2024-11-21 19:44:152024-11-21 19:44:15

Judging History

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

  • [2024-11-21 19:44:15]
  • 评测
  • 测评结果:WA
  • 用时:39ms
  • 内存:5272kb
  • [2024-11-21 19:44:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
//using i128 = __int128;
#define sz(a) (int)(a.size())
#define rep(x,a,b) for(int x = a; x < b; x++)
#define all(a) a.begin(), a.end()
#define uni(a) a.resize(unique(all(a)) - a.begin())
#define maxe(a) max_element(all(a))
#define mine(a) min_element(all(a))
#define lb(b,val) lower_bound(b.begin(), b.end(), val) - b.begin()
#define ub(b,val) upper_bound(b.begin(), b.end(), val) - b.begin()
#define fd(b,val) find(all(b), val) - b.begin()
#define ct(b,val) count(all(b), val)
#define bp(s) __builtin_popcountll(s)
#define fi first 
#define se second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define sp setprecision
const int mod = 998244353;
constexpr int N = 100005;
ll qmi(ll a, ll b){ll res = 1 % mod;while(b){if(b & 1) res = 1ll * res * a % mod;a = 1ll * a * a % mod;b >>= 1;}return res;}
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
ll add(ll &x, ll &y){x %= mod;y %= mod;ll res = x;res += 1ll * y;res %= mod;return res;}
ll minus(ll &x, ll &y){x %= mod;y %= mod;ll res = x;res -= 1ll * y;res %= mod;res += mod;res %= mod;return res;}
ll mul(ll &x, ll &y){x %= mod;y %= mod;ll res = x;res = 1ll * x * y % mod;res %= mod;return res;}
namespace binom {
    ll fac[N], ifac[N];
    int __ = []
    {
        fac[0] = 1;
        for (int i = 1; i <= N - 5; i++)
            fac[i] = fac[i - 1] * i % mod;
        ifac[N - 5] = qmi(fac[N - 5], mod - 2);
        for (int i = N - 5; i; i--)
            ifac[i - 1] = ifac[i] * i % mod;
        return 0;
    }();

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

    inline ll A(int n, int m)
    {
        if (n < m || m < 0) return 0;
        return fac[n] * ifac[n - m] % mod;
    }
}
using namespace binom;
void solve(){
    int n, m;
    cin >> n >> m;
    if(m == 1){
        cout << 0 << endl;
        return;
    }
    ll res = 0;
    int ctl, ctr;
    ll x;
    auto check = [&](ll p, ll q){
        ctl = 0;
        x = q;
        while(p % x == 0){
            if(x >= p) break;
            ctl++;
            x *= 1ll * q;
        }
        if(ctl == 0) return;
        if(ctl + ctr >= m - 2){
            rep(k, 1, min(ctl, m - 2) + 1){
                res -= 1ll * C(ctl, k) * C(ctr, m - 2 - k) % mod;     
                res %= mod;   
                res += mod;
                res %= mod;                      
            }                      
        }
        if(ctl + ctr < m - 1) return;
        rep(k, 1, min(ctl, m - 1) + 1){
            res -= 1ll * C(ctl, k) * C(ctr, m - 1 - k) % mod;      
            res %= mod;  
            res += mod;
            res %= mod;                      
        }                    
    };
    rep(i, 2, n + 1){
        res += 1ll * C(n - 1, m - 1);
        res %= mod;
        int st = sqrt(i + 1);
        ctr = n / i;
        ctr--;
        if(ctr >= m - 1){
            res -= C(ctr, m - 1) % mod; 
            res %= mod;  
            res += mod;
            res %= mod;               
        }
        if(ctr >= m - 2){
            res -= C(ctr, m - 2) % mod; 
            res %= mod;  
            res += mod;
            res %= mod;              
        }
        int o = i;
        rep(j, 2, st + 1){
            if(o % j == 0){
                check(i, j);
                while(o % j == 0){
                    o /= j;
                }
                if(o == 1) break;
            }
        }
        if(o != 1) check(i, o);
    }      
 

    cout << res << endl;
}
signed main(){
    int _ = 1;
    ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
    while(_--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 0ms
memory: 5044kb

input:

11 4

output:

1187

result:

ok 1 number(s): "1187"

Test #3:

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

input:

100000 99999

output:

17356471

result:

ok 1 number(s): "17356471"

Test #4:

score: 0
Accepted
time: 4ms
memory: 5072kb

input:

11451 1919

output:

845616153

result:

ok 1 number(s): "845616153"

Test #5:

score: 0
Accepted
time: 39ms
memory: 5232kb

input:

99998 12345

output:

936396560

result:

ok 1 number(s): "936396560"

Test #6:

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

input:

100000 1

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: -100
Wrong Answer
time: 39ms
memory: 5272kb

input:

100000 15

output:

379260049

result:

wrong answer 1st numbers differ - expected: '190067060', found: '379260049'