Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- //a * x^2 + b * x + c >= k
- long long a,b,c,k;
- bool yes (long long x) {
- if ((a * (x * x) + b * x + c) >= k) return true;
- else return false;
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T;
- cin >> T;
- for (int test_case = 1; test_case <= T; ++test_case) {
- cin >> a >> b >> c >> k;
- long long l = 0,r = 1e6;
- long long res = 0;
- while (l <= r) {
- long long mid = l + (r - l) / 2; // (l + r) / 2
- if (yes(mid)) {
- r = mid - 1;
- res = mid;
- } else {
- l = mid + 1;
- }
- }
- cout << res << '\n';
- }
- //~ cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement