a*x+b*y=c find nearest point to origin ; x>0

this question was asked on hackerrank in my college contest mnitcodefriday .plzz explain me the solution…
all a,b,c,are integers and answers x,y will be ints also

1 Like

find equation of line which is perpenducular to given line.
which is -bx+cy=d , you need to fine constant d.
since this line should pass to origin d will be zero.
so by solving this two equation -bx+cy=d and ax+by=c , you will get your answer.

3 Likes

why -bx+cy are u taking the variables b and c same as in ax+by=c
and x>0 so if we get x<=0 then our ans is x=1,y=(c-a)/b…thanks for your ans

ohh my bad completely forgot slope thing(m1*m2=-1) thanks …

According to #gandu007 … answer is …

x + 2y = 3, ax+by=c

-2x + 3y = 4, -bx+cy=d

2x + 4y = 6, 2 * ax+by=c

7y = 10

y = 10/7 => x = 1/7 … is the nearest point

2 Likes

x=1,y=(3-1)/2=1
is correct x,y are ints and x>0
thanks anyway, for stopping by i am upvoting you so u can ask yours not for explanation of earlier answer

you can edit my answer, i forgot to mention that little thing. Thanks for pointing it out.

@gandu007 thanks for your ans i am from mnit i needed to ask this thing too .i can’t believe that i forgot this thing . they teach it in school standard…

2 Likes