#include<bits/stdc++.h>
#define int long long
using namespace std;
int x, v, s, y;
bool check(int a, int b, int k, int x, int d) {
if (a * k >= d) return 1;
d = d - a * k;
int tmp = d / b;
if (k * x + (v - 1) * k * (k - 1) / 2 >= tmp) return 1;
return 0;
}
bool check1(int a, int b, int k, int x, int d) {
if (a * k > d) return 0;
d = d - a * k;
if (d % b != 0) return 0;
return 1;
}
int exgcd(int a, int b, int &n, int &m) {
if (b == 0) {
n = 1, m = 0;
return a;
}
int res = exgcd(b, a % b, m, n);
m = m - a / b * n;
return res;
}
void solve() {
scanf("%lld%lld%lld", &x, &v, &s);
if (v == 0) {
if (s == x * (x + 1) / 2) printf("0\n");
else printf("-1\n");
return ;
}else if (s == 0) {
if (x == 0) printf("0\n");
else printf("-1\n");
return ;
}else {
if (x * (x + 1) / 2 > s) {
printf("-1\n");
return ;
}
int d = s - x * (x + 1) / 2;
int a = v * (v + 1) / 2, b = v;
int l = 0, r = d / (v * (v + 1) / 2) + 114, ans = 0;
while (l <= r) {
int mid = (l + r) / 2;
int k = mid;
if (check(a, b, k, x, d)) {
ans = k;
r = mid - 1;
}else l = mid + 1;
}
if (check1(a, b, ans, x, d) == 0) {
ans++;
if (check1(a, b, ans, x, d) == 0) {
printf("-1\n");
return ;
}
}
printf("%lld\n", ans);
}
}
signed main() {
freopen("bike.in", "r", stdin);
freopen("bike.out", "w", stdout);
int T;
cin >> T;
while (T--) {
solve();
}
}Somebody needs it
这是 2026年10月31日 存档的第 2 版,不是当前版本。查看当前版本