/**
 * @author Daniel "3ICE" Berezvai
 */
public class Root {
	public static void main(String[] args) {
		if(args.length!=1 || Double.parseDouble(args[0])<0){
			System.out.println("Hello, please give me a positive number as a command line argument.");
		}else{
			int iter=0;
			double a=Double.parseDouble(args[0]);
			double low=0;
			double hi=a; //3ICE: Valószínűleg elég lenne az intervallumot a szám feléig venni.
			double mid=(low+hi)/2;
			double guess=mid*mid;
			double off=guess-a;
			//3ICE: Végtelen ciklusba futottam irracionális gyökű (pl. 2) és kis számoknál.
			//3ICE: Legyen 100 lépés maximum.
			while(Math.abs(off)>0.01 && iter<100){
				iter++;
				mid=(low+hi)/2;
				guess=mid*mid;
				off=guess-a;
				//3ICE: Sokkal szebb a kimenet, ha Math.round()-on keresztül írunk ki mindent.
				//3ICE: A gyök kettőt és pi-t viszont így csúnyán számolja.
				//3ICE: (Lépések nem látszanak, mindig 2..2-ben keres. Lásd lent.)
				//3ICE: Megoldás: Dinamikus pontatlanság-választó. Kis számoknál pontos, nagynál kerekít.
				if(mid<10) System.out.println("Trying interval "+low+" .. "+hi);
				else System.out.println("Trying interval "+Math.round(low)+".."+Math.round(hi));
				System.out.println("got "+mid+", whose square is "+guess);
				System.out.print("We are off by: "+off+", so ");
				if(off<0) {low=mid; System.out.println("setting low to "+low+" (case: -)");}
				else {hi=mid; System.out.println("setting hi to "+hi+" (case: +)");}
				System.out.println();
			}
				System.out.println();
				System.out.println("Result after "+iter+" iterations:");
				System.out.println("Root of " + a + " is approximately " + mid);
		}
	}
}
//3ICE: Kerekített kimenet takarja a részleteket:
// C:\ELTE\Java\GY\1>java Root 3.14159265359
// Trying 0..3, got 2, whose square is 2, which is off by: -0.6741915533173355
// case: -; Setting low to 1.570796326795
// Trying 2..3, got 2, whose square is 6, which is off by: 2.410059822023496
// case: +; Setting hi to 2.3561944901925003
// Trying 2..2, got 2, whose square is 4, which is off by: 0.7137215655860385
// case: +; Setting hi to 1.9634954084937501
// Trying 2..2, got 2, whose square is 3, which is off by: -0.018788136057408256
// case: -; Setting low to 1.7671458676443752
// Trying 2..2, got 2, whose square is 3, which is off by: 0.33782842921637446
// case: +; Setting hi to 1.8653206380690626
// Trying 2..2, got 2, whose square is 3, which is off by: 0.15711057519249794
// case: +; Setting hi to 1.8162332528567189
// Trying 2..2, got 2, whose square is 3, which is off by: 0.06855882672079883
// case: +; Setting hi to 1.7916895602505472
// Trying 2..2, got 2, whose square is 3, which is off by: 0.02473474712000856
// case: +; Setting hi to 1.7794177139474612
// Trying 2..2, got 2, whose square is 3, which is off by: 0.0029356559783786373
// case: +; Setting hi to 1.7732817907959182
// 
// Result after 9 iterations:
// Root of 3.14159265359 is approximately 1.7732817907959182

//3ICE: Pontosabb kimenet túl spammy és átláthatatlan:
// C:\ELTE\Java\GY\1>java Root 3.14159265359
// Trying 0.0..3.14159265359, got 1.570796326795, whose square is 2.4674011002726646, which is off by: -0.6741915533173355
// case: -; Setting low to 1.570796326795
// Trying 1.570796326795..3.14159265359, got 2.3561944901925003, whose square is 5.551652475613496, which is off by: 2.410059822023496
// case: +; Setting hi to 2.3561944901925003
// Trying 1.570796326795..2.3561944901925003, got 1.9634954084937501, whose square is 3.8553142191760386, which is off by: 0.7137215655860385
// case: +; Setting hi to 1.9634954084937501
// Trying 1.570796326795..1.9634954084937501, got 1.7671458676443752, whose square is 3.122804517532592, which is off by: -0.018788136057408256
// case: -; Setting low to 1.7671458676443752
// Trying 1.7671458676443752..1.9634954084937501, got 1.8653206380690626, whose square is 3.4794210828063745, which is off by: 0.33782842921637446
// case: +; Setting hi to 1.8653206380690626
// Trying 1.7671458676443752..1.8653206380690626, got 1.8162332528567189, whose square is 3.298703228782498, which is off by: 0.15711057519249794
// case: +; Setting hi to 1.8162332528567189
// Trying 1.7671458676443752..1.8162332528567189, got 1.7916895602505472, whose square is 3.210151480310799, which is off by: 0.06855882672079883
// case: +; Setting hi to 1.7916895602505472
// Trying 1.7671458676443752..1.7916895602505472, got 1.7794177139474612, whose square is 3.1663274007100086, which is off by: 0.02473474712000856
// case: +; Setting hi to 1.7794177139474612
// Trying 1.7671458676443752..1.7794177139474612, got 1.7732817907959182, whose square is 3.1445283095683787, which is off by: 0.0029356559783786373
// case: +; Setting hi to 1.7732817907959182
// 
// Result after 9 iterations:
// Root of 3.14159265359 is approximately 1.7732817907959182

//3ICE: Az eredmény természetesen ugyan az.