Advertisement
TawratNibir

Untitled

Nov 18th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main() {
  5.     long double x, low, mid, high;
  6.     cin >> x;
  7.     low = 1;
  8.     high = x;
  9.     mid = low + (high - low)/2;
  10.     int p = 2000000;
  11.     while(p--) {
  12.         if(mid * mid > x) {
  13.             high = mid;
  14.             mid = low + (high - low)/2;
  15.         }
  16.         else{
  17.             low = mid;
  18.             mid = low + (high - low)/2;
  19.         }
  20.         if(low>high) {
  21.             break;
  22.         }
  23.     }
  24.     cout << fixed << setprecision(70) << mid;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement