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

来源:互联网 发布:女生做seo 编辑:程序博客网 时间:2024/06/13 18:55
C. Mike and Chocolate Thieves
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 exactlyk times more than the previous one. The value ofk (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at mostn chocolates (if they intend to take more, the deal is cancelled) and that there wereexactly 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 fixedn, but not fixed k) ism. 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 ofn 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 suchn.

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 onen satisfying the rumors, print the smallest one.

If there is no such n for a false-rumouredm, print  - 1.






解法:二分+暴力


#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>using namespace std;__int64 solve (__int64 x){    __int64 num=0;    for(__int64 i=2;i<=x;i++){        if(i*i*i>x)            return num;        num+=( x/(i*i*i) );    }    return num;}int main(){    __int64 n;    //printf("%I64d\n",solve(895903132760));    scanf("%I64d",&n);    int i,j;    __int64 num=0;    __int64 l=0;    __int64 r=0x3fffffffffffffff;    __int64 mid;    while(1){        mid=(l+r)/2;        num=solve(mid);        if(l==r)            break;        if(num>=n)            r=mid;        else if(num<n)            l=mid+1;    }    if(num==n)        printf("%I64d\n",mid);    else        printf("-1\n");    return 0;}


0 0
原创粉丝点击