Responsive Ads Here

Sunday 6 August 2017

Min value of x Show Topic Tags

problem id:--http://practice.geeksforgeeks.org/problems/min-value-of-x/0

In this problem you need to find the Positive integer root of the given equation
Since given equation is this ax^2+bx+c>=k
First convert it into normal form
ax^+bx+(c-k)>=0
Now find the +ve root of the quadratic solution . and if it's a decimal number Then just take ceil
of that value.  That's all . Happy coding :)

code:--

#include <bits/stdc++.h>

using namespace std;
#define sc(x)   scanf("%d",&x)
int main()
{
int t;
sc(t);
while(t--)
{
double a,b,c,k;
cin>>a>>b>>c>>k;
double x1;
x1=(-b+sqrt(b*b-4*a*(c-k)))/(2*a);
cout<<ceil(x1)<<'\n';
}
return 0;
}


2 comments:

  1. You should also give its complexity and what if I entered some values for which no positive roots are available. As the GFG approach is also not optimal for negative roots.
    But yeah its better than the GFG approach.

    ReplyDelete
    Replies
    1. Since GFG problem have positive values that's why i have only considered positive values. and for the complexity you can see my solution it's taking constant time complexity.
      Happy coding!

      Delete