Advertisement
sajid161

17:2

May 2nd, 2021
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. ll function_value(ll a,ll b,ll c,ll x)
  4. {
  5.     return (a*x*x+b*x+c);
  6. }
  7. ll find_x(ll a,ll b,ll c,ll k)
  8. {
  9.     ll l=0,r=1000000,ans;
  10.     while(l<=r)
  11.     {
  12.         ll mid=(l+r)/2;
  13.  
  14.         if(function_value(a,b,c,mid)<k)
  15.         {
  16.             l=mid+1;
  17.         }
  18.         else
  19.  
  20.         {
  21.             ans=mid;
  22.             r=mid-1;
  23.  
  24.         }
  25.     }
  26.     return ans;
  27. }
  28. using namespace std;
  29. int main()
  30. {
  31.     int t;
  32.     cin>>t;
  33.     while(t--)
  34.     {
  35.         ll a,b,c,k;
  36.         cin>>a>>b>>c>>k;
  37.         cout<<find_x(a,b,c,k)<<"\n";
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement