京东笔试第一题,序列
/**
* 求1 2 2 3 3 3 4 4 4 4 5 5 5 5 5.... 第k项数是多少。
* 通过
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double n = Double.parseDouble(scanner.nextLine());
if (n <= 0) {
System.out.println(0);
return;
}
if (n > Math.pow(10, 18)) {
System.out.println(0);
return;
}
double x = Math.sqrt(1 + 8 * n);
double y = (x - 1) / 2;
System.out.println((int) (Math.ceil(y)));
}