fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define max 1000000000
  5.  
  6. typedef unsigned long long int ull;
  7.  
  8. ull r,t;
  9.  
  10. bool check (int x)
  11. {
  12. return (((2*x +2*r -1)*x) <= t);
  13. }
  14.  
  15. int check()
  16. {
  17. int low=0, high=max,mid;
  18. while(low<high)
  19. {
  20. mid= (low+ high+1)/2;
  21. if(check(mid))
  22. low=mid;
  23. else
  24. high=mid-1;
  25. }
  26. return low;
  27. }
  28.  
  29. int main() {
  30. // your code goes here
  31. int test;
  32. cin>>test;
  33. for(int i=1;i<=test;i++)
  34. {
  35. cin>>r>>t;
  36. ull ans=check();
  37. cout<<"Case #"<<i<<": "<<ans<<endl;
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 2688KB
stdin
5
1 9
1 10
3 40
1 1000000000000000000
10000000000000000 1000000000000000000
stdout
Case #1: 1
Case #2: 2
Case #3: 3
Case #4: 707106780
Case #5: 972