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