序號(hào)乘方
Description
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'.
有無限的人站在一排,索引從1開始。一個(gè)用i作索引的人有(i*i)的力量。你有力量P。你需要說出你能用你的力量殺死的最大人數(shù)是多少。只有當(dāng)P >= 'X'時(shí),你才能殺死一個(gè)'X'力量的人,并且在殺死他后,你的力量減少'X'。
Input
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
第一行包含一個(gè)整數(shù)“T”——測(cè)試用例的數(shù)量,下一行包含一個(gè)整數(shù)“P”——您的Power.Constraints:1<=T<=100001<=P<=1000000000000000
Output
For each testcase Output The maximum Number of People You can kill.
對(duì)于每個(gè)測(cè)試用例,輸出您可以殺死的最大人數(shù)。
Sample Input
1
14
Sample Output
3
Solution
public class KillMaxPeople {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int caseNum = in.nextInt();
for(int i = 0; i < caseNum; i++){
long p = in.nextLong();
getKillMaxPeople(p);
}
}
public static void getKillMaxPeople(long p){
long i = 1;
p -= i * i;
long count = 0;
while(p >= 0){
count++;
i++;
p -= i * i;
}
System.out.println(count);
}
}