Monk's Encounter with Polynomial
Practice
3.8 (222 votes)
Algorithms
Approved
Binary search
Easy
Math
Open
Sorting
Problem
90% Success 25614 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Our monk, while taking a stroll in the park, stumped upon a polynomial ( A X2 + B X +C ) lying on the ground. The polynomial was dying! Being considerate, our monk tried to talk and revive the polynomial. The polynomial said:

I have served my purpose, and shall not live anymore. Please fulfill my dying wish. Find me the least non-negative integer Xo, that shall make my value atleast K i.e., A Xo2 + B Xo + C >= K .

Help our Monk fulfill the polynomial's dying wish!


Input:
The first line contains an integer T. T test cases follow.
Each test case consists of four space-separated integers A, B, C and K.

Output:
For each test case, output the answer in a new line.

Constraints:
1 ≤ T ≤ 105
1 ≤ A,B,C ≤ 105
1 ≤ K ≤ 1010

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
25 votes
Tags:
AlgorithmsBinary SearchBit manipulationEasySearchingTwo pointer
Points:20
17 votes
Tags:
AlgorithmsBinary SearchEasySearching
Points:20
200 votes
Tags:
ApprovedBinary SearchEasyOpenSorting