HDU 4282 A very hard mathematic problem 二分
A very hard mathematic problem
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=4282
Description
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
TThere 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
Sample Output
HINT
题意
给你K,求X^Z+Y^Z+X*Y*Z=K有多少个解
题解:
枚举X,Z,二分Y
代码
#include<iostream>
#include<cstdio>
#include<cmath> using namespace std; int k,maxa; inline int f(int a,int b,int x)
{
return pow(x*1.0,b*1.0)+pow(a*1.0,b*1.0)+a*b*x-k;
} bool judge(int a,int b)
{
int L,R,M,t;
L=a+;R=maxa;
if(f(a,b,L)>||f(a,b,R)<) return false;
while(L<=R)
{
M=(L+R)>>;
t=f(a,b,M);
if(t==) return true;
else if(t>) R=M-;
else L=M+;
}
return false;
} int main()
{
int ans,a,b;
while(scanf("%d",&k)==&&k)
{
ans=;
for(b=;b<=;b++)
{
maxa=pow(k*1.0,1.0/b);
for(a=;a<=maxa;a++)
{
if(judge(a,b))
ans++;
}
}
printf("%d\n",ans);
}
return ;
}
HDU 4282 A very hard mathematic problem 二分的更多相关文章
- HDU 4282 A very hard mathematic problem --枚举+二分(或不加)
题意:问方程X^Z + Y^Z + XYZ = K (X<Y,Z>1)有多少个正整数解 (K<2^31) 解法:看K不大,而且不难看出 Z<=30, X<=sqrt(K) ...
- hdu 4282 A very hard mathematic problem
由于k的范围是0-2^31,而且x,y,z都是正整数,由题易知道2<=z<31,1<=x<y;所以直接枚举就好了!!! #include<iostream> #in ...
- hdu 4972 A simple dynamic programming problem(高效)
pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic progra ...
- HDU 2254 奥运(矩阵高速幂+二分等比序列求和)
HDU 2254 奥运(矩阵高速幂+二分等比序列求和) ACM 题目地址:HDU 2254 奥运 题意: 中问题不解释. 分析: 依据floyd的算法,矩阵的k次方表示这个矩阵走了k步. 所以k ...
- HDU 5954 - Do not pour out - [积分+二分][2016ACM/ICPC亚洲区沈阳站 Problem G]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5954 Problem DescriptionYou have got a cylindrical cu ...
- hdu 4282 枚举,非二分
http://acm.hdu.edu.cn/showproblem.php?pid=4282 对于方程X^Z + Y^Z + XYZ = K,已知K求此方程解的个数,其中要求X<Y,Z>1 ...
- HDU 2141 Can you find it? (二分)
题目链接: Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/ ...
- HDU 2236:无题II(二分搜索+二分匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=2236 题意:中文题意. 思路:先找出最大和最小值,然后二分差值,对于每一个差值从下界开始枚举判断能不能二分匹配. ...
- hdu 1839 Delay Constrained Maximum Capacity Path 二分/最短路
Delay Constrained Maximum Capacity Path Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu. ...
随机推荐
- nginx 负载均衡相关知识
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Igor Sysoev ...
- 获取当前的 viewController
- (UIViewController *)currentController { UIViewController *result = nil; UIWindow *window = [ ...
- Sikulix IDE简介
打开sikuklixIDE 这里介绍下使用方式 可以看到左边的menu 有查找,鼠标动作和键盘动作 我们先用百度搜索做个例子 打开firefox,输入www.baidu.com 点击左边的Click, ...
- 增加duilib edit控件的提示功能和多种文字颜色
转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/41786407 duilib的CEditUI控件内部使用了win32的原生 ...
- UDP模式与TCP模式的区别
1.TCP有连接状态,而UDP没有. 2.TCP应用层使用无需考虑包的大小及发送情况,而UDP需要. 3.TCP中IP包大小的决定者是Socket,而UDP为应用层.
- dispatch_once单例初始化
static GHCache *instance = nil; /** * 单例,静态初始化方法 * * @return 返回一个单例 */ + (GHCache*)shareCache{ sta ...
- Eclipse中用Link方式安装Maven插件(转载)
标签: it 分类: 开发软件 1.工具下载: Eclipse4.2 jee版本(注意是Jee,不是标准版的eclipse) 下载地址:http://www.eclipse.org/downloads ...
- Camera拍照声设定
在某些国家(比如Japan),为了防止偷拍,强制拍照声是需要从Speaker出来的(即使插入耳机的情况下). 实现该功能比较简单的方法就是将拍照声类型设置为Ringtone 或 Alarm 或 Not ...
- eclipse gradle 自动打包
直接在eclipse项目中建立一个文件,文件名为build.gradle.其实还可以用eclipse再项目上面右击,export->Android->Generate Gradle bui ...
- LeetCode(5) - Longest Palindromic Substring
这道题要求的是给你一个string, 如“adcdabcdcba",要求返回长度最大的回文子字符串.这里有两个条件,一是子字符串,而是回文.用纯暴力搜索的话,需要用到O(n^3)的时间,必然 ...