fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4.  
  5. int s(int k, int m) {
  6. if (m <= k) return m * (m + 1) / 2;
  7. int a = k * (k + 1) / 2;
  8. int r = m - k;
  9. int b = r * k - r * (r + 1) / 2;
  10. return a + b;
  11. }
  12.  
  13. void solve() {
  14. int k, x;
  15. cin >> k >> x;
  16. int l = 1, h = 2 * k - 1, ans = h;
  17. while (l <= h) {
  18. int m = (l + h) / 2;
  19. if (s(k, m) >= x) { ans = m; h = m - 1; }
  20. else l = m + 1;
  21. }
  22. cout << ans << '\n';
  23. }
  24.  
  25. int32_t main() {
  26. ios::sync_with_stdio(false);
  27. cin.tie(nullptr);
  28. int t; cin >> t;
  29. while (t--) solve();
  30. }
  31.  
Success #stdin #stdout 0.01s 5328KB
stdin
7
4 6
4 7
1 2
3 7
2 5
100 1
1000000000 923456789987654321
stdout
3
4
1
4
3
1
1608737403