OJ序号乘方

import java.util.Scanner;

/*序号乘方
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。索引为“i”的人的强度为(i*i)。
你有力量“P”。
你需要知道你能用你的力量杀死的最大人数是多少。
你只能用力量“X”杀死一个人,如果P>=“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
第一行包含一个整数'T'-测试用例的数量,接下来的每一行都包含一个整数'P'-您的权力约束:1<=T<=100001<=P<=10000000000000

Output

For each testcase Output The maximum Number of People You can kill.


Sample Input 1

1
14
Sample Output 1

3

1 4 9*/
public class Main {
    static Scanner scanner=new Scanner(System.in);
    public static void main(String args[]){
        int T=scanner.nextInt();
        for (int t=0;t<T;t++){
            int p=scanner.nextInt();
            System.out.println(killPeople(p));
        }
    }

    /**
     * @param p
     * @return
     */
    private static int killPeople(int p) {
        int count=0;
        int index=1;
        while(p>0){
            p=p-index*index;
            index++;
            if(p>=0){
            count++;
            }
        }
        return count;
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值