Interstellar (traversal)

Topic description

Spacecraft is a complex and sophisticated instrument. The loss of the aircraft is mainly concentrated in the process of launch and landing. Scientists estimate based on experimental data that if there is a loss of x degree during the launch process, then during the landing process, There will be x 2 degree of wear and tear, if the total wear and tear of the ship exceeds its durability, the aircraft will explode and crash. Ask an aircraft with a durability of h. Assuming that there is no loss during flight, in order to ensure that it can reach its destination safely, only considering the integer solution, at most how much loss can it withstand during the launch process?

Enter description:

Each input contains a test case. Each test case contains a row of an integer h (1 <= h <= 10^18).

Output description:

Output a line with an integer representing the result.
Example 1

enter

10

output

2
 1 import java.util.Scanner;
 2 
 3 /**
 4  * 
 5  * 星际穿越
 6  * @author Dell
 7  *
 8  */
 9 public class Main {
10 static public long h = 10;
11 static public long x;
12 static public void f() {
13 for (long i = (int) Math.sqrt(h); i >=0 ; i--) {
14         if (i*i+i<=h) {
15             x = i;
16             break;
17         }
18     }
19 }
20 public static void main(String[] args) {
21     Scanner sc = new Scanner(System.in);
22     h = sc.nextLong();
23     f();
24     System.out.println(x);
25 }
26 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325141301&siteId=291194637