Advertisement
Derga

Untitled

Feb 21st, 2023
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iomanip>
  2. #include <iostream>
  3.  
  4. int main() {
  5.   std::ios_base::sync_with_stdio(false);
  6.   std::cin.tie(nullptr);
  7.  
  8.   double a;
  9.   std::cin >> a;
  10.  
  11.   double left = 0.;
  12.   double right = a;
  13.   double DELTA = 0.00000000000001;
  14.   while (right - left > DELTA) {
  15.     double mid = left + (right - left) / 2;
  16.     if (mid * mid - mid + sqrt(mid) < a) {
  17.       left = mid;
  18.     } else {
  19.       right = mid;
  20.     }
  21.   }
  22.  
  23.   std::cout << std::setprecision(6) << (right + left) / 2;
  24.  
  25.   return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement