algo. cube_root

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Double flt = sc.nextDouble(), l = -10000.0, r = 10000.0;
while (r - l > 1e-8) {
Double mid = (l + r) / 2;
if (mid*mid*mid >= flt) r = mid;
else l = mid;
}
System.out.print(String.format("%.6f", l));
}
}

algo. cube_root
http://elwinliu.com/2024/09/08/algo. cube-root/
Author
Elwin
Posted on
September 8, 2024
Licensed under