fork download
  1. t = int(input())
  2.  
  3. for _ in range(t):
  4. n, a = map(int, input().split())
  5. l, r, mid, res = 0, n, -1, -1
  6. t = 2 * (n * a - n)
  7. while l <= r:
  8. mid = (l + r) // 2
  9. if t >= mid * mid - mid:
  10. res = mid
  11. l = mid + 1
  12. else:
  13. r = mid - 1
  14. print(res)
Success #stdin #stdout 0.04s 9552KB
stdin
3
2 4
5 1
8 4
stdout
2
1
7