Codeforces Round #361 (Div. 2) C - Mike and Chocolate Thieves
来源:互联网 发布:女生做seo 编辑:程序博客网 时间:2024/06/13 18:55
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.
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.
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;}
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves
- Codeforces Round #361 (Div. 2) C - Mike and Chocolate Thieves
- Codeforces Round #361 (Div. 2)C. Mike and Chocolate Thieves
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves (二分法)
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves(二分判断)
- CF Round #361 (Div. 2) 689C. Mike and Chocolate Thieves
- CodeForces-689C.Mike and Chocolate Thieves
- CodeForces 689C Mike and Chocolate Thieves
- Codeforces-689C-Mike and Chocolate Thieves
- Codeforces #361C. Mike and Chocolate Thieves 二分 数学
- Mike and Chocolate Thieves(CF #361 Div. 2)
- Codeforces 678C Mike and Chocolate Thieves(二分)
- Codeforces 689C Mike and Chocolate Thieves (二分)
- Codeforces 689.C Mike and Chocolate Thieves 二分+数学
- Codeforces 689C. Mike and Chocolate Thieves(二分)
- Codeforces 689C Mike and Chocolate Thieves【二分+思维】
- 关于linux和windows对udp收包差异引发的问题排查
- js操作数组
- 运维那几点心得
- C++ 关于声明,定义,类的定义,头文件作用,内、外链接
- angular实现将三目运算写入HTML中
- Codeforces Round #361 (Div. 2) C - Mike and Chocolate Thieves
- 设计模式(3)-结构型-桥接模式(Bridge)
- (OK)(OK) seem-tools-CLI-semi-auto_4_vbox.sh
- 学习easyUI 扩展的Editable DataGrid组件
- Java总结系列之集合体系
- Druid使用起步—在javaWeb项目中配置监控
- CentOS7安装GitLab的步骤
- Maven 手动添加 JAR 包到本地仓库
- Linux 下编译安装软件,找不到共享库 xx.so 的解决办法