问题描述
There are Infinite People Standing in a row, indexed from 1.A person having index 'i' has strength of (i*i).You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P.You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength decreases by 'X'.
输入
First line contains an integer 'T' - the number of testcases,Each of the next 'T' lines contains an integer 'P'- Your Power.Constraints:1<=T<=100001<=P<=1000000000000000
输出
For each testcase Output The maximum Number of People You can kill.
示例输入
1
14
示例输出
3
思路
略
代码
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int casesnum = sc.nextInt();
while(casesnum>0){
long power = sc.nextLong();
long n = 1;
long sum = 0;
while (true){
sum += n*n;
if(sum > power)
break;
n ++;
}
System.out.println(n-1);
casesnum --;
}
}
}