OJ序号乘方

import java.util.Scanner;/*序号乘方
DescriptionThere 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。InputFirst 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<=10000000000000OutputFor each testcase Output The maximum Number of People You can kill.Sample Input 11
14
Sample Output 131 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;}
}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部