fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. signed main(){
  4. long double c, d;
  5. cin >> c >> d;
  6. long double l = 0, r = 1e12;
  7. long double mid;
  8. for(int i = 0; i < 100; i++){
  9. mid = (l + r) * 0.5;
  10. if(c + sqrt(mid) > d + mid * mid) l = mid;
  11. else if(c + sqrt(mid) < d + (mid * mid)) r = mid;
  12. }
  13. cout << fixed << setprecision(15) << mid << endl;
  14. }
Success #stdin #stdout 0.01s 5284KB
stdin
22 8
stdout
4.000000000000000