QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#875765#10020. Heroes and Illusionsasdfsdf#WA 19ms6452kbC++231.4kb2025-01-30 12:34:072025-01-30 12:34:08

Judging History

This is the latest submission verdict.

  • [2025-01-30 12:34:08]
  • Judged
  • Verdict: WA
  • Time: 19ms
  • Memory: 6452kb
  • [2025-01-30 12:34:07]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define MOD 998244353
#define MAX 202020
ll mpow(ll x, ll y = MOD - 2) {
	ll mul = x;
	ll ans = 1;
	while (y) {
		if (y & 1) ans = (ans * mul) % MOD;
		y >>= 1;
		mul = (mul * mul) % MOD;
	}
	return ans;
}
ll ifact[MAX];
ll fact[MAX];
void solve() {
	ll N, K;
	cin >> N >> K;
	if (K == 0) {
		cout << 1 << '\n';
		return;
	}
	ll i;
	ll ans = 0;
	vector<ll> v;
	ll sol = (N + 1) * (N + 1) - 4 * K;
	if (sol < 0) {
		cout << 0 << '\n';
		return;
	}
	sol = sqrt(sol);
	sol = N + 1 - sol;
	sol >>= 2;
	for (i = max(1ll, sol - 20); i <= min(K, sol + 20); i++) {
		if (K % i == 0) {
			v.push_back(i);
			if (K / i != i) v.push_back(K / i);
		}
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	for (auto i : v) {
		ll e = i;
		ll o = K / i;
		if (o + e != N + 1) continue;
		e--;
		ll res = fact[N];
		res = (res * ifact[e]);
		res %= MOD;
		res = (res * ifact[N - e]);
		res %= MOD;
		ans += res;
		ans %= MOD;
	}
	cout << ans << '\n';
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int T;
	cin >> T;
	int i;
	fact[0] = 1;
	int X = 100'010;
	for (i = 1; i <= 100'100; i++) fact[i] = (fact[i - 1] * i) % MOD;
	ifact[X] = mpow(fact[X]);
	for (i = X; i >= 1; i--) ifact[i - 1] = (ifact[i] * i) % MOD;
	while (T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
5 9

output:

10

result:

ok 1 number(s): "10"

Test #2:

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

input:

4
3 4
6 12
6 11
12 30

output:

3
35
0
286

result:

ok 4 number(s): "3 35 0 286"

Test #3:

score: -100
Wrong Answer
time: 19ms
memory: 6204kb

input:

100000
1 0
1 1
2 0
2 1
2 2
2 3
3 0
3 1
3 2
3 3
3 4
3 5
3 6
4 0
4 1
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
5 0
5 1
5 2
5 3
5 4
5 5
5 6
5 7
5 8
5 9
5 10
5 11
5 12
5 13
5 14
5 15
6 0
6 1
6 2
6 3
6 4
6 5
6 6
6 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
6 15
6 16
6 17
6 18
6 19
6 20
6 21
7 0
7 1
7 2
7 3
7 4
7 5
7 ...

output:

1
1
1
0
3
0
1
0
0
4
3
0
0
1
0
0
0
5
0
10
0
0
0
0
1
0
0
0
0
6
0
0
15
10
0
0
0
0
0
0
1
0
0
0
0
0
7
0
0
0
21
0
35
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
8
0
0
0
0
28
0
0
56
35
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
9
0
0
0
0
0
36
0
0
0
84
0
126
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
10
0
0
0
0
0
0...

result:

wrong answer 90322nd numbers differ - expected: '539764346', found: '0'