Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分

C. Mike and Chocolate Thieves

题目连接:

http://www.codeforces.com/contest/689/problem/C

Description

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.

Sample Input

8

Sample Output

54

Hint

题意

给你n,让你找到一个最小的数t,使得这个数t以内,恰好存在n个四元组

这个四元组需要满足 a,ak,ak^2,ak^3,且这四个数都小于等于t

题解

二分答案,然后我们暴力枚举k,然后算四元组有多少个就好了。

代码

#include<bits/stdc++.h>
using namespace std;
long long n;
long long mul(long long x){
    return x*x*x;
}
long long cal(long long k){
    long long sum = 0;
    for(int i=2;i<=1e6;i++)
        sum+=k/mul(i);
    return sum;
}
int main(){
    cin>>n;
    long long l = 0,r = 1e18;
    while(l<=r){
        long long mid=(l+r)/2;
        if(cal(mid)>=n)r=mid-1;
        else l=mid+1;
    }
    if(cal(r+1)==n)cout<<r+1<<endl;
    else cout<<"-1"<<endl;
}

你可能感兴趣的:(Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分)