QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#776452#9553. The HermitwindStriderWA 80ms8692kbC++203.4kb2024-11-23 18:45:192024-11-23 18:45:19

Judging History

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

  • [2024-11-23 18:45:19]
  • 评测
  • 测评结果:WA
  • 用时:80ms
  • 内存:8692kb
  • [2024-11-23 18:45:19]
  • 提交

answer

#include<bits/stdc++.h>

using pii = std::pair<int, int>;

using i64 = long long;

static constexpr int mod = 998244353;

class combMath
{
public:
    static constexpr int size = 2e5;
    i64 fact[size + 1];
    i64 finv[size + 1];
    i64 inve[size + 1];
    static constexpr int mod = 998244353;
    void factor()
    {
        fact[0] = 1; fact[1] = 1;
        inv();
        finv[0] = 1;
        finv[1] = inve[1];
        for (int i = 2; i <= size; ++i) fact[i] = fact[i - 1] * i % mod, finv[i] = finv[i - 1] * inve[i] % mod;
    }
    void inv()
    {
        inve[1] = 1;
        for (int i = 2; i <= size; ++i)
        {
            inve[i] = (mod - mod / i) * inve[mod % i] % mod;
        }
    }
public:
    combMath() { factor(); }
    i64 power(i64 x, i64 p)
    {
        i64 temp = p, ans = 1;
        while (temp)
        {
            if (temp & 1) ans = ans * x % mod;
            temp >>= 1;
            x = x * x % mod;
        }
        return ans;
    }
    i64 getInv(i64 x)
    {
        return power(x, mod - 2);
    }
    i64 inv(i64 x)
    {
        return inve[x];
    }
    i64 facInv(i64 x)
    {
        return finv[x];
    }
    i64 getFac(i64 obj)
    {
        return fact[obj];
    }
    i64 perm(i64 n, i64 m, bool mode)
    {
        if (mode) return fact[n] * finv[n - m] % mod;
        else return fact[n] / fact[n - m];
    }
    i64 comb(i64 n, i64 m, bool mode = 1)
    {
        if (mode) return fact[n] * finv[n - m] % mod * finv[m] % mod;
        else return fact[n] / fact[n - m] / fact[m];
    }
    i64 stirling(i64 n, i64 m) // 'n' balls into 'm' boxes, boxes DO NOT differ while balls differ.
    {
        i64 ans = 0;
        for (int i = 0; i < m; ++i)
            ans = (ans + (i & 1 ? -1 : 1) * comb(m, i, 1) * power(m - i, n) % mod) % mod;
        ans = ans * finv[m] % mod;
        return (ans + mod) % mod;
    }
    i64 catalan(int n, int mode) // n different nums pop in a stack in an certain order, how many ramifications there will be.
    {
        std::vector<i64> dp(n + 1, 1);
        if (mode) for (int i = 1; i <= n; ++i) dp[i] = dp[i - 1] * (4LL * i % mod - 2) % mod * inv(i + 1) % mod;
        else for (int i = 1; i <= n; ++i) dp[i] = dp[i - 1] * (4 * i - 2) / (i + 1);
        return dp[n];
    }
} cm;

const int N = 1e5 + 1;

using namespace std;

int cnt[N];

void solve()
{
    for (int i = 2; i <= 1e5; ++i)
    {
        int tmp = i;
        for (int j = 2; j <= i / j; ++j)
        {
            while (tmp % j == 0) tmp /= j, ++cnt[i];
        }
        if (tmp > 1) ++cnt[i];
    }
    // for (int i = 2; i < 100; ++i)
    // {
    //     std::cout << cnt[i] << "\n";
    // }
    int m,n;
    std::cin >> m >> n;

    long long suml = cm.comb(m,n) * n % mod;
    for(int i = 1;i <= m;i++){
        //cout << cnt[i] << endl;
        //std::cout << suml << endl;
        if(i == 1){
            suml = (suml + mod - cm.comb(m-1,n-1) % mod) % mod;
        }
        else{
            //cnt[i]++;

            long long mm = m / i - 1;
            for(int j = 0;j <= cnt[i];j++){
                if(j + mm + 1 >= n && j + 1 <= n)
                    suml = (suml + mod -(cm.comb(cnt[i],j) * cm.comb(mm,n-j-1))%mod)%mod;
            }
        }
    }
    std::cout << suml;
}

int main()
{
    // int t;
    // std::cin >> t;
    // while (t--)
    // {
    //     solve();
    // }
    solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 80ms
memory: 8564kb

input:

4 3

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 76ms
memory: 8684kb

input:

11 4

output:

1187

result:

ok 1 number(s): "1187"

Test #3:

score: 0
Accepted
time: 78ms
memory: 8616kb

input:

100000 99999

output:

17356471

result:

ok 1 number(s): "17356471"

Test #4:

score: 0
Accepted
time: 80ms
memory: 8692kb

input:

11451 1919

output:

845616153

result:

ok 1 number(s): "845616153"

Test #5:

score: -100
Wrong Answer
time: 77ms
memory: 8616kb

input:

99998 12345

output:

937364469

result:

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