QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#875763#10020. Heroes and Illusionsasdfsdf#TL 29ms6508kbC++231.1kb2025-01-30 12:28:352025-01-30 12:28:37

Judging History

This is the latest submission verdict.

  • [2025-01-30 12:28:37]
  • Judged
  • Verdict: TL
  • Time: 29ms
  • Memory: 6508kb
  • [2025-01-30 12:28:35]
  • 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;
	for (i = 1; i * i <= K; i++) {
		if (K % i == 0) {
			v.push_back(i);
			if (K / i != i) v.push_back(K / i);
		}
	}
	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: 1ms
memory: 6364kb

input:

1
5 9

output:

10

result:

ok 1 number(s): "10"

Test #2:

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

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: 0
Accepted
time: 29ms
memory: 5376kb

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:

ok 100000 numbers

Test #4:

score: -100
Time Limit Exceeded

input:

100000
100000 5000050000
100000 5000049999
100000 5000049998
100000 5000049997
100000 5000049996
100000 5000049995
100000 5000049994
100000 5000049993
100000 5000049992
100000 5000049991
100000 5000049990
100000 5000049989
100000 5000049988
100000 5000049987
100000 5000049986
100000 5000049985
10000...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result: