QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#772681#9553. The HermitClarusWA 0ms3612kbC++205.6kb2024-11-22 21:11:102024-11-22 21:11:10

Judging History

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

  • [2024-11-22 21:11:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-11-22 21:11:10]
  • 提交

answer

#include <bits/stdc++.h>

using LL = long long;

constexpr int inf = 1E9;

template<class T>
constexpr T power(T a, LL b) 
{
    T res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res *= a;
        }
        b >>= 1;
        a *= a;
    }
    return res;
}

template<int P>
struct MInt
{
    int x;
    static int Mod;

    constexpr MInt() : x{} {}
    constexpr MInt(LL x) : x{norm(x % getMod())} {}
    
    constexpr static int getMod() 
    {
        if (P) return P;
        else return Mod;
    }
    constexpr static void setMod(int mod) 
    {
        Mod = mod;
    }
    constexpr int norm(int x) const 
    {
        if (x < 0) 
        {
            x += getMod();
        }
        if (x >= getMod()) 
        {
            x -= getMod();
        }
        return x;
    }
    constexpr int val() const 
    {
        return x;
    }
    explicit constexpr operator int() const 
    {
        return x;
    }
    constexpr MInt operator-() const 
    {
        MInt res;
        res.x = norm(getMod() - x);
        return res;
    }
    constexpr MInt inv() const 
    {
        assert(x != 0);
        return power(*this, getMod() - 2);
    }
    constexpr MInt &operator*=(MInt rhs) & 
    {
        x = 1LL * x * rhs.x % getMod();
        return *this;
    }
    constexpr MInt &operator+=(MInt rhs) & 
    {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr MInt &operator-=(MInt rhs) & 
    {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr MInt &operator/=(MInt rhs) & 
    {
        return *this *= rhs.inv();
    }
    constexpr MInt &operator++() &
    {
        x = norm(x + 1);
        return *this;
    }
    constexpr MInt operator++(int)
    {
        MInt temp = *this;
        ++(*this);
        return temp;
    }
    friend constexpr MInt operator*(MInt lhs, MInt rhs) 
    {
        MInt res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr MInt operator+(MInt lhs, MInt rhs) 
    {
        MInt res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr MInt operator-(MInt lhs, MInt rhs) 
    {
        MInt res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr MInt operator/(MInt lhs, MInt rhs) 
    {
        MInt res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr std::istream &operator>>(std::istream &is, MInt &a) 
    {
        LL v;
        is >> v;
        a = MInt(v);
        return is;
    }
    friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) 
    {
        return os << a.val();
    }
    friend constexpr bool operator<(MInt lhs, MInt rhs)
    {  
        return lhs.val() < rhs.val();  
    }
    friend constexpr bool operator==(MInt lhs, MInt rhs) 
    {
        return lhs.val() == rhs.val();
    }
    friend constexpr bool operator!=(MInt lhs, MInt rhs) 
    {
        return lhs.val() != rhs.val();
    }
};

template<>
int MInt<0>::Mod = int(1e9) + 7;

template<int V, int P>
constexpr MInt<P> inv = MInt<P>(V).inv();

constexpr int P = 998244353;
using Z = MInt<P>;

namespace comb
{
    int n = 0;
    std::vector<Z> _fac{1}, _invfac{1}, _inv{0};

    void init(int m) 
    {
        m = std::min(m, Z::getMod() - 1);
        if (m <= n) return;

        _fac.resize(m + 1);
        _invfac.resize(m + 1);
        _inv.resize(m + 1);

        for (int i = n + 1; i <= m; i++) 
        {
            _fac[i] = _fac[i - 1] * i;
        }

        _invfac[m] = _fac[m].inv();
        for (int i = m; i > n; i--) 
        {
            _invfac[i - 1] = _invfac[i] * i;
            _inv[i] = _invfac[i] * _fac[i - 1];
        }

        n = m;
    }

    Z fac(int m) 
    {
        if (m > n) init(2 * m);
        return _fac[m];
    }
    Z invfac(int m) 
    {
        if (m > n) init(2 * m);
        return _invfac[m];
    }
    Z inv(int m) 
    {
        if (m > n) init(2 * m);
        return _inv[m];
    }
    Z binom(int n, int m) 
    {
        if (n < m || m < 0) return 0;
        return fac(n) * invfac(m) * invfac(n - m);
    }
}

std::vector<int> minp, primes;
 
void sieve(int n) 
{
    minp.assign(n + 1, 0);
    primes.clear();
    
    for (int i = 2; i <= n; i++)
    {
        if (minp[i] == 0) 
        {
            minp[i] = i;
            primes.emplace_back(i);
        }
        for (auto p : primes) 
        {
            if (i * p > n)
            {
                break;
            }
            minp[i * p] = p;
            if (p == minp[i])
            {
                break;
            }
        }
    }
}

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

    int n, m;
    std::cin >> m >> n;

    sieve(m);

    std::vector<int> a(m + 1), b(m + 1);
    for (int i = 1; i <= m; i++)
    {
    	b[i] = (m - i) / i;
    	a[i] = 1;
    	int j = i;
    	for (auto p : primes)
    	{
    		int c = 0;
    		while (j % p == 0)
    		{
    			c++;
    			j /= p;
    		}
    		a[i] *= (c + 1);
    		if (j == 1) { break; }
    	}
    	a[i]--;
    }

    Z ans = comb::binom(m, n) * n;
    for (int i = 1; i <= m; i++)
    {
    	int l = n - 1 - std::min(n - 1, b[i]);
    	int r = std::min(n - 1, a[i]);
    	for (int j = l; j <= r; j++)
    	{
    		Z sub = comb::binom(a[i], j) * comb::binom(b[i], n - 1 - j);
    		ans -= sub;
    	}
    }

    std::cout << ans << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3440kb

input:

11 4

output:

1185

result:

wrong answer 1st numbers differ - expected: '1187', found: '1185'