首页 技术 正文
技术 2022年11月10日
0 收藏 712 点赞 4,912 浏览 2731 个字

原题:

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896