A very hard mathematic problem

Haoren is very good at solving mathematic problems. Today he is working a problem like this:
  Find three positive integers X, Y and Z (X < Y, Z > 1) that holds
   X^Z + Y^Z + XYZ = K
  where K is another given integer.
  Here the operator “^” means power, e.g., 2^3 = 2 * 2 * 2.
  Finding a solution is quite easy to Haoren. Now he wants to challenge more: What’s the total number of different solutions?
  Surprisingly, he is unable to solve this one. It seems that it’s really a very hard mathematic problem.
  Now, it’s your turn.
Input
  There are multiple test cases.
  For each case, there is only one integer K (0 < K < 2^31) in a line.
  K = 0 implies the end of input.
  
Output
  Output the total number of solutions in a line for each test case.
Sample Input

9
53
6
0

Sample Output

1
1
0

Hint
9 = 1^2 + 2^2 + 1 * 2 * 2
53 = 2^3 + 3^3 + 2 * 3 * 3
.

.
.

思路: 使用二分查找,但对x,y,z三个数中的哪一个进行查找需要判断,为了使时间复杂度最小,对三个数中范围最大的进行二分;
首先可得z的大致范围为2~31;
x为1~pow(k,1.0/z);
y范围最大,所以对y进行二分
.
.

.

代码:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int Max;
int k;bool ok(int x,int z){int l = x+1,r = Max;while(l<=r){int mid = (l+r)/2;if(pow(x*1.0,z*1.0)+pow(mid*1.0,z*1.0)+x*mid*z<k)l = mid+1;else if(pow(x*1.0,z*1.0)+pow(mid*1.0,z*1.0)+x*mid*z>k)r = mid-1;elsereturn true;}return false;
}int main()
{while(cin >> k && k!=0){int ans = 0;for(int z=2;z<31;z++){Max = pow(k,1.0/z);for(int x=1;x<=Max;x++){if(ok(x,z))ans++;}}cout << ans << endl;}return 0;
}

Day8 二分-----A very hard mathematic problem相关推荐

  1. HDU 4282 A very hard mathematic problem 二分题目

    http://acm.hdu.edu.cn/showproblem.php?pid=4282 题解:http://www.cnblogs.com/E-star/archive/2012/09/11/2 ...

  2. HDU-4282 A very hard mathematic problem 技巧枚举+二分

    题意 xz+yz+x∗y∗z=kx^z+y^z+x*y*z = k ( y>x&&z>1y>x&&z>1) 给我们这个等式让我们找出这里面有多少 ...

  3. 2021算法竞赛入门班第二节课【递归、分治、二分】练习题

    目录 华华给月月准备礼物[二分] The Biggest Water Problem[模拟] Bits[递归模拟 / 未完成] [NOIP2004]FBI树[树的后序遍历] [USACO 2009 D ...

  4. bzoj4755: [Jsoi2016]扭动的回文串 manacher+二分+Hash

    bzoj4755: [Jsoi2016]扭动的回文串 Description JYY有两个长度均为N的字符串A和B. 一个"扭动字符串S(i,j,k)由A中的第i个字符到第j个字符组成的子串 ...

  5. cf1562D Two Hundred Twenty One

    cf1562D Two Hundred Twenty One 题意: 定义一个前缀和公式:a1−a2+a3−a4+..=∑i=1n(−1)i−1∗aia_{1}-a_{2}+a_{3}-a_{4}+. ...

  6. 一些noip模拟题一句话题解

    Problem A: 序列 Time Limit: 10 Sec  Memory Limit: 256 MB Submit: 12  Solved: 9 [Submit][Status][Web Bo ...

  7. C语言求数列最小公倍数,C语言复习---获取最小公倍数(公式法:两个数相乘等于最小公倍数乘以最大公约数)...

    Android 图片浏览器 从原来位置放大至全屏显示 android 图片浏览器 特点: 1.从网络加载图片,只需要传图片地址数组即可 2.点击图片,从原来位置放大至全屏 3.支持手势操作 4.完全自 ...

  8. 2016区域赛前冲刺训练

    UPD 2016.10.23 shift-and (2题) Codeforces 训练 现在已经完成了: 191 [Codeforces Round #377] (6/6) Div 2 A Buy a ...

  9. 每周记录(4月底停更了qvq)

    1月6日 旋转卡壳 闵可夫斯基和 1月13日 期末复习 1月20日 网络流前4道题 一场失败的期末考试 写寒假作业 bzoj [HNOI2008]明明的烦恼(90分) prufer序列 正睿 画画图 ...

  10. php金字塔代码掏空中间,php练习——打印半金字塔、金字塔、空心金字塔、菱形、空心菱形...

    Codeforces Round #377 (Div. 2) D. Exams(二分答案) D. Exams Problem Description: Vasiliy has an exam peri ...

最新文章

  1. jar java classpath_win7中java编程工具安装 java环境变量设置
  2. Lucene 源码分析之倒排索引(三)
  3. Python 数据分析包:pandas 基础
  4. 深划痕需要大面积补漆吗_剐蹭了需要立马补漆吗?这些小技巧能省不少!
  5. vim使用—实现程序的自动补齐(C语言)
  6. HDU-1102-Constructing Roads(并查集)
  7. CV新赛事|常见天气分类
  8. rocketmq新扩容的broker没有tps_揭秘 RocketMQ 新特性以及在金融场景下的实践
  9. linux mint下安装vnc,VNC远程连接Linux mint桌面
  10. google appid申请
  11. matlab进化树的下载,mega(进化树构建软件)下载 v7.0.14免费版
  12. CRMEB多商户版跨域问题解决
  13. TILERA--Makefile实例
  14. Riverbed SteelHead 9.5.0
  15. Flutter 3.0 极光推送
  16. 做一个简单计算器(两个数的加减乘除)扣扣116119409
  17. android实现基于表情识别和敲击识别的认证系统,表情识别支持自动的连续隐藏式拍照
  18. ZOJ3380- Patchouli's Spell Cards(概率DP+计数)
  19. 用FireFox火狐浏览器的3D Tilt 插件查看网页3D视图效果
  20. floyed 算法计算最短路径

热门文章

  1. 一个前端程序员的费曼技巧练习
  2. Zigbee协议栈无线通信系统
  3. php 61850,IEC61850客户端
  4. 计算机网络原理之运输层
  5. 常见不等式考察(一)——Jensen不等式
  6. 包含h3c、cisco、F5、华为、中兴、juniper等网络设备巡检命令整理,建议点赞收藏
  7. 结构张量 matlab 图像,图像处理中 结构张量(structure tensor)
  8. 无线覆盖技术的重要性
  9. 新东方 词根词缀 excel_14张图搞定高中英语词汇常见词缀词根!
  10. 常见的计算机端口及服务