Advertisement
newb_ie

Untitled

Sep 13th, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. //a * x^2 + b * x + c >= k
  5. long long a,b,c,k;
  6. bool yes (long long x) {
  7. if ((a * (x * x) + b * x + c) >= k) return true;
  8. else return false;
  9. }
  10.  
  11. int main () {
  12. ios::sync_with_stdio(false);
  13. cin.tie(nullptr);
  14. cout.tie(nullptr);
  15. int T;
  16. cin >> T;
  17. for (int test_case = 1; test_case <= T; ++test_case) {
  18. cin >> a >> b >> c >> k;
  19. long long l = 0,r = 1e6;
  20. long long res = 0;
  21. while (l <= r) {
  22. long long mid = l + (r - l) / 2; // (l + r) / 2
  23. if (yes(mid)) {
  24. r = mid - 1;
  25. res = mid;
  26. } else {
  27. l = mid + 1;
  28. }
  29. }
  30. cout << res << '\n';
  31. }
  32. //~ cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
  33. }
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement