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

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

题目链接:http://codeforces.com/contest/689/problem/C


题意:有4个小偷偷东西,后面一个偷的是前面一个的K倍。有m种可能性,每个小偷偷的东西不能超过一个容量,求小偷的最小的容量n。

思路:假设容量为x,则可能性有cou=x/(2^3)+x/(3^3)+x/(4^3)+.....种。暴力二分求x。二分次数最多为64次,每一次最多进行10^6求cou,与m进行判断比较。

代码:

#include<bits/stdc++.h>
using namespace std;
__int64 gg[];
int main()
{
__int64 i,m;
for(i=; i<=; i++)
gg[i]=i*i*i;
scanf("%I64d",&m);
__int64 l=,r=1e18,mid;
int flag=;
__int64 ans;
while(l<r)
{
mid=(l+r)>>;
__int64 cou=;
for(i=; gg[i]<=mid; i++)
cou+=mid/gg[i];
cout<<l<<" "<<r<<" "<<mid<<" "<<cou<<endl;
if(cou>m) r=mid-;
else if(cou<m) l=mid+;
else
{
r=mid;
flag=;
ans=mid;
}
}
if(flag) cout<<ans<<endl;
else cout<<"-1"<<endl;
return ;
}

Codeforces 689C. Mike and Chocolate Thieves 二分的更多相关文章

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

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

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

    原题: Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the l ...

  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. Sass、Less编译器koala及koala不支持中文字体的解决方法

    一款很好用的Sass编译器,还可以编译Less.coffeescript等 去官网下载适合自己电脑的版本 http://koala-app.com/index-zh.html 打开后拖动或者打开项目目 ...

  2. 【Flutter】Flutter 一些常用库

    Flutter社区和资源传送门 新: 慕课网<Flutter入门与案例实战>   |   中文网<Flutter实战>电子书 字体图标生成 http://fluttericon ...

  3. IP分组交付和转发

    1:交付 网络层监视底层物理网络对分组的处理过程叫做交付,分为直接交付和间接交付 1.1:直接交付 直接交付时,分组的终点是一台与交付着连接在同一个网络上的主机,发生在俩种情况下,分组的源点和终点都在 ...

  4. python入门-操作列表

    1 Python根据缩进来进行判断代码行与前一个代码行的关系 for name in names: print(name) names = ['baker','david','philp','rose ...

  5. jpa 一对一

    实体   Manager package entity; import javax.persistence.Column; import javax.persistence.Entity; impor ...

  6. leetcode976

    public class Solution { public int LargestPerimeter(int[] A) { var list = A.OrderByDescending(x => ...

  7. css上下或者上中下 自适应布局

    方法就是头部不变,中间和底部绝对定位 *{ margin: ; padding: ; } div{ text-align: center; font-size: 30px; } .header,.fo ...

  8. hibernate-list

    Hibernate多表关联查询类: 1. sql查询两个或两个以上的字段,默认情况下,list中封装的是Object[],长度与所查询的字段数一致.这种方式获取的数据只能通过index下标获取. su ...

  9. xcopy 复制目录及子目录

    例:将a文件夹内的所有内容(包括子文件夹)复制到b文件夹 xcopy a\* b /y /e /i /q 说明: /y:不弹出“确认是否覆写已存在目标文件”的提示 /e:复制文件及子文件夹内所有内容, ...

  10. UNION会自动删除重复项,union与union all的差异

    UNION会自动删除重复项,刷选出部分字段的时候要注意了,如果刷选出来的两个字段的值完全相同就会剩下一个. UNION ALL 和 UNION 不同之处在于 UNION ALL 会将左右两个查询的结果 ...