the-honk/royal institute computer science masterclass 2021/from ancient babylon to quantum computing/babylonian square root.java

19 lines
346 B
Java
Raw Normal View History

2021-07-10 11:23:46 +00:00
import java.util.Scanner;
public class Babylonian
{
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
long x = input.nextLong();
double a = 2;
while (Math.abs(a - (x / a)) > 1)
{
a = (a + (x / a)) / 2;
}
System.out.println(a);
}
}