问题 K: 立方
时间限制: 1 Sec 内存限制: 128 MB
题目描述
今年乐乐开始学编程了,上几天刚刚解决了一个平方数的问题,问题是这样的:随便告诉你一个不超过 1 个亿的正整数,请你算出不超过该数的所有立方数的个数。
但是,如果这个超过 1 亿,是一个 18 位正整数,或 28 位的正整数呢?
乐乐不会算,你会吗?
输入
只有一行且只有一个正整数:n
输出
只有一行且只有一个正整数:不超过 n 的平方数个数
样例输入 Copy
100
样例输出 Copy
4
提示
111 = 1 222 = 8
333 = 27 444 = 64
555 = 125 但是 125 > 100
对于 30%的数据, 1 <= n <= 10^8
对于 70%的数据, 1 <= n <= 10^18
对于 100%的数据, 1 <= n <= 10^28
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
/**
*
* @author 3612999a
*/
public class Main {
public static void main(String[] args) {
int cnt=0;
Scanner cin=new Scanner(System.in);
String str = cin.nextLine();
BigInteger n = new BigInteger(str);
long l=1,r=100000000000L;
while(l<=r){
long mid=(l+r)>>1;
String s=Long.toString(mid);
BigInteger x=new BigInteger(s);
if(x.multiply(x).multiply(x).compareTo(n)>0){
r=mid-1;
}
else{
l=mid+1;
}
}
System.out.println(r);
}
}