序號(hào)乘方

序號(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);
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容