QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#769585#9553. The HermithxsjWA 47ms5248kbC++145.3kb2024-11-21 18:19:542024-11-21 18:19:56

Judging History

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

  • [2024-11-21 18:19:56]
  • 评测
  • 测评结果:WA
  • 用时:47ms
  • 内存:5248kb
  • [2024-11-21 18:19:54]
  • 提交

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;
    rep(i, 2, n + 1){
        res += C(n - 1, m - 1);
        res %= mod;
        int st = sqrt(i + 1);
        int ctl, ctr;
        ll x;
        ctr = n / i;
        ctr--;
        if(ctr >= m - 1){
            res -= C(ctr, m - 1) % mod; 
            res %= mod;  
            res += mod;
            res %= mod;               
        }
        //if(i == 4) cout << res << endl;
 
        if(ctr >= m - 2){
            res -= C(ctr, m - 2) % mod; 
            res %= mod;  
            res += mod;
            res %= mod;              
        }
        //if(i == 4) cout << res << endl;
         
        rep(j, 2, st + 1){
            if(i % j == 0){
                ctl = 0;
                x = j;
                while(i % x == 0){
                    if(x >= i) break;
                    ctl++;
                    x *= j;
                }
                if(ctl != 0){
                    //cout << ctl << " " << ctr << endl;
                    if(ctl + ctr >= m - 2){   
                        res += mod;
                        res %= mod;    
                        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) continue;
                    rep(k, 1, min(ctl, m - 1) + 1){
                        res -= 1ll * C(ctl, k) * C(ctr, m - 1 - k) % mod;      
                        //if(i == 4) cout << C(ctl, k) * C(ctr, m - 1 - k) << endl;
                        res %= mod;  
                        res += mod;
                        res %= mod;                      
                    }                    
                }
                if(i / j != j && j != 1){
                    int t = i / j;
                    ctl = 0;
                    x = t;
                    while(i % x == 0){
                        if(x >= i) break;
                        ctl++;
                        x *= t;
                    }
                    if(ctl == 0) continue;
                    if(ctl + ctr >= m - 2){   
                        res += mod;
                        res %= mod;    
                        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;                      
                        }                      
                    }
                    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;                      
                    }                
                }
            }
        }
        
    }      
 

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

詳細信息

Test #1:

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

input:

4 3

output:

7

result:

ok 1 number(s): "7"

Test #2:

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

input:

11 4

output:

1187

result:

ok 1 number(s): "1187"

Test #3:

score: 0
Accepted
time: 47ms
memory: 5124kb

input:

100000 99999

output:

17356471

result:

ok 1 number(s): "17356471"

Test #4:

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

input:

11451 1919

output:

845616153

result:

ok 1 number(s): "845616153"

Test #5:

score: -100
Wrong Answer
time: 41ms
memory: 5192kb

input:

99998 12345

output:

35428201

result:

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