Bad news came to Mike’s village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief’s bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.
Input
The single line of input contains the integer m (1 ≤ m ≤ 1015) — the number of ways the thieves might steal the chocolates, as rumours say.
Output
Print the only integer n — the maximum amount of chocolates that thieves’ bags can carry. If there are more than one n satisfying the rumors, print the smallest one.
If there is no such n for a false-rumoured m, print - 1.
Example
Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1
Note
In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), (1, 3, 9, 27), (2, 4, 8, 16), (2, 6, 18, 54), (3, 6, 12, 24), (4, 8, 16, 32), (5, 10, 20, 40), (6, 12, 24, 48).
There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
分析:很明显我们要二分枚举n,根据题意我们又可以知道 n = x * k ^ 3 ,所以我们可以枚举 k ,然后得到每一种k其方案数目为 n / (k*k*k) 。
注意: 二分枚举的上界 一定要为 0x 8个3f ,不能开小了,当时直接 上界为 1e15 果断wa,因为n的最大好像为 4(3?)e15 反正比1e15大。以后如果对于二分枚举的上界直接定为0x8个3f, 反正都是log的。
所以k的枚举上界,我们也要注意 ,不能直接卡1e5,这样的话你基本会wa在12组上 ,还是一样的道理,因为n的最大大于1e15,所以k我们也要大一些。
这些小细节真的烦人,但是却少一点都不行,以后还是好好分析题目 ,不要在这种低级错误上失败。
代码
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 1e6+11; // 开到了 1e6 枚举的过程中 会有截断,所以不会都枚举到1e6
const int M = 1e6+11;
const int inf = 0x3f3f3f3f;
const LL inff= 0x3f3f3f3f3f3f3f3f; // 二分上界
LL f(LL n){
LL ans=0;
for(LL i=2;i<N;i++){
LL t=n/(i*i*i);
if(t==0) break;
ans+=t;
}
return ans;
}
int main(){
LL m; cin>>m;
LL le,ri,mid;
le=0; ri=inff;
LL ans=-1;
while(le<=ri){
mid=(le+ri)>>1;
LL num=f(mid);
if(num>=m){
if(num==m) ans=mid;
ri=mid-1;
}else le=mid+1;
}
if(ans==-1) puts("-1");
else cout<<ans<<endl;
return 0;
}