Files
python/TangDou/AcWing/BinarySearch/790_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

50 lines
977 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
/*
浮点数不能太大,10000>=a>=-10000
*/
double sqrt(int n) {
double x = n;
for (int i = 1; i <= 100; i++) x = (x * x + n) / (2 * x);
return x;
}
double sqrt3(int n) {
double x = n;
for (int i = 1; i <= 100; i++) x = (2 * x * x * x + n) / (3 * x * x);
return x;
}
double sqrt4(int n) {
double x = n;
for (int i = 1; i <= 100; i++) x = (3 * x * x * x * x + n) / (4 * x * x * x);
return x;
}
double sqrt5(int n) {
double x = n;
for (int i = 1; i <= 100; i++) x = (4 * x * x * x * x * x + n) / (5 * x * x * x * x);
return x;
}
int main() {
// 求n的平方根和立方根
double n;
cin >> n;
// 平方根
printf("%.6lf\n", sqrt(n));
// 立方根
printf("%.6lf\n", sqrt3(n));
// 4次方根
printf("%.6lf\n", sqrt4(n));
// 5次方根
printf("%.6lf\n", sqrt5(n));
return 0;
}