fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. long long a, b, c;
  10.  
  11.  
  12. float gpa(int n) {
  13. return (float)(2 * a + 3 * b + 4 * c + 5 * n) / (a + b + c + n);
  14. }
  15.  
  16. long double f(long double x)
  17. {
  18. return x * x;
  19. }
  20.  
  21. int main() {
  22. long double c, left = 0, right = 1e15, middle, eps =10e-10;
  23. cin >> c;
  24. if (c < 0) cout << "No solutions!";
  25. else {
  26. while (fabs(right - left) > eps) {
  27. middle = (left + right) / 2.0;
  28. if (f(middle) - c < 0) left = middle;
  29. else right = middle;
  30. }
  31. cout << fixed;
  32. cout.precision(2);
  33. cout << right;
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5504KB
stdin
6=
stdout
2.45