是谁场切T3
可能因为我暑假整天刷二分的原因吧(
#include <bits/stdc++.h>
#define int long long
using namespace std;
int T, n, m, k, ans;
bool check(int x) {
if(n <= x) return 1;
int t = n / x;
if(t > m) return 0;
if(t > 1) {
int low = n*(t-1)/2;
if (low > k) return 0;
}
double c = (double)t*n - (double)x*t*(t+1) / 2.0;
if(c > (double)k + 1e-9) return 0;
if(c < (double)k - 1e-9) return 1;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
ans = 0;
bool flag = 0;
cin >> n >> m >> k;
if(m == 1){
cout << (n == 1?0:-1) << '\n';continue;
}
if(n == 1){
cout << 0 << '\n';continue;
}
if(n > k){
int t = (n - k - 1) / k;
ans += t;
n -= t * k;
}
while(n > 1){
int l = (n + m - 1) / m,r = n, res = n;
while(l <= r) {
int mid = (l + r) / 2;
if(check(mid)) {
res = mid;
r = mid - 1;
}
else l = mid + 1;
}
if(res >= n) {
flag = 1;
cout << -1 << '\n';
break;
}
n = res; ans++;
}
if(!flag) cout << ans << '\n';
}
return 0;
}