原题:

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

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

Sample Input

Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1

Hint

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.

提示: 代码中fun(x)函数表示 在n=x时,返回可以构成的最大组合种数。(n=T*k^3,对于指定的一个k ,T可取1~T个)。

  所以即寻找一个最小的x,满足fun(x) == m 。

  fun(x)单调增,所以用二分查找,复杂度满足题目要求。

  二分时注意 1. while(l<=r)       要用小于等于号,缺等号wrong answe。(二分查找法的基本要求)  2.types == m_types 时,r=mid-1。(以便寻找最小的n,当多个连续数相等时,取最左侧的)。

  还有一个地方,fun(10e14) = 10e15     可知,当m取极端情况10e15,对应最大的n为10e14 ,所以定义r变量一定要至少定义成10e15,(long long 数据范围10e18)。

代码:

#include<cstdio>
#include<cstring>
#include<iostream> using namespace std; #define MAX(x,y) (((x)>(y)) ? (x) : (y))
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#define ABS(x) ((x)>0?(x):-(x))
#define ll long long
const int inf = 0x7fffffff;
const int maxn=1e15+; ll fun(ll x)
{
ll sum=;
for(ll i=; i*i*i<=x; i++){
sum += x/(i*i*i);
}
return sum;
} int main()
{
ll l=,r=10e15,mid,ans=-;//fun(10e14) == 10e15; 所以最大的n可能取值为10e15 (极端有10e15种方法的时候)
ll m_types;
cin>>m_types;
while(l<=r){ //l=minimum n, r=maximum n ; =要加 方便找到最小的那个数
mid=l+(r-l)/;
ll types=fun(mid);
if(types < m_types)
l=mid+;
else if(types > m_types)
r=mid-;
else{ //相等也要取左半部分,因为要找最小的n(找最大的也有方法)
ans=mid;
r=mid-;
}
}
cout<<ans<<endl;
return ;
}

CodeForces 689C Mike and Chocolate Thieves (二分)的更多相关文章

  1. Codeforces 689C. Mike and Chocolate Thieves 二分

    C. Mike and Chocolate Thieves time limit per test:2 seconds memory limit per test:256 megabytes inpu ...

  2. CodeForces 689C Mike and Chocolate Thieves (二分+数论)

    Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...

  3. CodeForces 689C Mike and Chocolate Thieves (二分最大化最小值)

    题目并不难,就是比赛的时候没敢去二分,也算是一个告诫,应该敢于思考…… #include<stdio.h> #include<iostream> using namespace ...

  4. 689C - Mike and Chocolate Thieves 二分

    题目大意:有四个小偷,第一个小偷偷a个巧克力,后面几个小偷依次偷a*k,a*k*k,a*k*k*k个巧克力,现在知道小偷有n中偷法,求在这n种偷法中偷得最多的小偷的所偷的最小值. 题目思路:二分查找偷 ...

  5. codeforces 689C C. Mike and Chocolate Thieves(二分)

    题目链接: C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit per test 256 megabyte ...

  6. 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 ...

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

    C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  8. CodeForces 689C  Mike and Chocolate Thieves

    题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412145 题目大意:给定一个数字n,问能不能求得一个最小的整 ...

  9. codeforces 361 C - Mike and Chocolate Thieves

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Bad ...

随机推荐

  1. 阿里 RocketMQ 安装与简介

    一.简介 官方简介: l  RocketMQ是一款分布式.队列模型的消息中间件,具有以下特点: l  能够保证严格的消息顺序 l  提供丰富的消息拉取模式 l  高效的订阅者水平扩展能力 l  实时的 ...

  2. 移动平台对 meta 标签的定义

    一.meta 标签分两大部分:HTTP 标题信息(http-equiv)和页面描述信息(name). 1.http-equiv 属性的 Content-Type 值(显示字符集的设定) 说明:设定页面 ...

  3. java SpringUtil获取bean

    package com.whaty.framework.common.spring; import java.io.PrintStream; import org.springframework.be ...

  4. hiho一下120周 后缀数组一·重复旋律

    后缀数组一·重复旋律 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为长度为 N 的数构成的数列. 小Hi ...

  5. [转]STL中vector转数组(实际是数组的指针)

    感谢:http://topic.csdn.net/t/20050429/20/3976956.html 感谢:http://yzyanchao.blogbus.com/logs/47796444.ht ...

  6. HDU-2222 Keywords Search(AC自动机--模板题)

    题目大意:统计一共出现了多少次模板串. 题目分析:AC自动机的模板题.不过这题有坑,相同的模板串不能只算一次. 代码如下: # include<iostream> # include< ...

  7. 三个loading小动画实例

    直接贴代码: <!DOCTYPE html><html><head>    <meta charset="utf-8">    &l ...

  8. 用DotNetBar设计的 Gradient Buttons 漂亮按钮

       http://www.webdesignerwall.com/demo/css-buttons.html public class GradientButtons : DevComponents ...

  9. SpringMVC学习系列(2) 之 经典的HelloWorld实现

    前一篇简单介绍了Spring MVC的一些知识,下面就要开始学习如何把Spring MVC运用到具体的项目中去. 首先还是从一个简单的Hello World项目说起: 我机器的开发环境为: Ubunt ...

  10. Spring Framework----定时任务的执行和调度

    1. 简介 spring framework 为任务的异步执行和调度提供了抽象接口分别是:TaskExecutor 和 TaskScheduler,spring 对这些接口的进一步实现支持线程池或者将 ...