Advertisement
Derga

Untitled

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