题解:P16228 [蓝桥杯 2026 省 A] 读取指令
首先
显然如果
下面证明:
只要说明在集合
-
-
-
-
\dots -
因此区间数最多为
设这个区间为
如果从中想给定
即可。
参考代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read() {
int num = 0, nev = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') nev = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') { num += ch - '0'; num *= 10; ch = getchar();}
return num / 10 * nev;
}
signed main() {
int T = read();
while (T --) {
int n = read(), c = read(), w = read();
if (!w) {
cout << w << endl;
continue;
}
if (w % c) {
puts("-1");
continue;
}
w /= c;
if (w > n * (n + 1) / 2) {
puts("-1");
continue;
}
int ans = 2;
for (int N = 1; N <= n && N * N + N <= 2 * w; N ++) {
if ((2 * w - N * N - N) % (2 * N) == 0 && (2 * w - N * N - N) / (2 * N) + N <= n) {
ans = 1;
break;
}
}
cout << ans << '\n';
}
return 0;
}