fork(5) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main() {
  5. int t;
  6. scanf("%d", &t);
  7. while(t--) {
  8. int a, n;
  9. scanf("%d%d", &n, &a);
  10. int l = 0, r = n, mid, res = -1;
  11. while(l <= r) {
  12. mid = (l + r) / 2;
  13. if((ll)n*a - (ll)mid*(mid+1)/2 >= n-mid) {
  14. res = mid;
  15. l = mid + 1;
  16. } else r = mid - 1;
  17. }
  18. printf("%d\n", res);
  19. }
  20. return 0;
  21. }
Success #stdin #stdout 0s 4176KB
stdin
3
2 4
5 1
8 4
stdout
2
1
7