QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#795209#9553. The HermitGordios_knotWA 458ms38672kbC++141.4kb2024-11-30 18:39:042024-11-30 18:39:04

Judging History

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

  • [2024-11-30 18:39:04]
  • 评测
  • 测评结果:WA
  • 用时:458ms
  • 内存:38672kb
  • [2024-11-30 18:39:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

namespace D {
	typedef long long ll;
	const int p = 998244353;
	const int N = 1e5 + 5;
	ll qp(ll a, ll b) {
        ll z = 1;
        while(b) {
            if(b & 1) z = 1ll * z * a % p;
            a %= p;
            a = a * a;
            a %= p;
            b >>= 1;
        }
        return z;
    }
	ll fac[N], ifac[N];
	ll C(int a, int b)  {
		if (a < b || b < 0) return 0;
		return (((fac[a] * ifac[b]) % p) * ifac[a - b]) % p;
	}
	unordered_map<int, unordered_map<int, ll> > nums;
	ll ans = 0;
	void work() {
		ll n, m;
		cin >> m >> n;
		fac[0] = 1;
		for (int i = 1; i < N; i++) fac[i] = (fac[i - 1] * i) % p;
		ifac[N - 1] = qp(fac[N - 1], p - 2);
		for (int i = N - 1; i; i--) ifac[i - 1] = (ifac[i] * i) % p;
		for (int i = 1; i <= m; i++) {
			nums[i][1] = 1;
		}
		for (int i = 1; i <= m; i++) {
			for (int j = 2 * i; j <= m; j += i) {
				for (auto it = nums[i].begin(); it != nums[i].end() && it->first < n; it++) {
					nums[j][it->first + 1] = (nums[j][it->first + 1] + it->second) % p;
				}
			}
		}
		ans = (C(m, n) * n) % p;
		for (int i = 1; i <= m; i++) {
			for (auto it = nums[i].begin(); it != nums[i].end(); it++) {
				ans = (((ans - it->second * C(m / i - 1, n - it->first)) % p) + p) % p;
			}
		}
		cout << ans << '\n';
	}
}
int main (void) {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	D::work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3

output:

7

result:

ok 1 number(s): "7"

Test #2:

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

input:

11 4

output:

1187

result:

ok 1 number(s): "1187"

Test #3:

score: 0
Accepted
time: 458ms
memory: 38672kb

input:

100000 99999

output:

17356471

result:

ok 1 number(s): "17356471"

Test #4:

score: 0
Accepted
time: 14ms
memory: 8780kb

input:

11451 1919

output:

845616153

result:

ok 1 number(s): "845616153"

Test #5:

score: 0
Accepted
time: 417ms
memory: 38536kb

input:

99998 12345

output:

936396560

result:

ok 1 number(s): "936396560"

Test #6:

score: 0
Accepted
time: 23ms
memory: 27984kb

input:

100000 1

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: -100
Wrong Answer
time: 425ms
memory: 38496kb

input:

100000 15

output:

190072311

result:

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