fork download
  1. import math
  2.  
  3. def min_turns(h, d):
  4. k = int((math.isqrt(8*h - 7) - 1) // 2)
  5.  
  6. if d <= k:
  7. return d
  8. else:
  9. return k + 2*(d - k)
  10.  
  11.  
  12. t = int(input())
  13. for _ in range(t):
  14. h, d = map(int, input().split())
  15. print(min_turns(h, d))
Success #stdin #stdout 0.09s 14180KB
stdin
5
3 2
1 1
5 3
2 4
10 7
stdout
3
2
4
7
11