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. ...
随机推荐
- table应用之colspan与rowspan
<table border=" borderColorDark="#66ff33"> <tr> <td rowspan=" ali ...
- 《Windows程序设计第5版》学习进度备忘
书签:另外跳过的内容有待跟进 __________________学习资源: <Windows程序设计第5版珍藏版> __________________知识基础支持: _________ ...
- Python单例模式研究
方法一 import threading class Singleton(object): __instance = None __lock = threading.Lock() # used t ...
- 你可能不知道的30个Python语言的特点技巧
1 介绍 从我开始学习Python时我就决定维护一个经常使用的“窍门”列表.不论何时当我看到一段让我觉得“酷,这样也行!”的代码时(在一个例子中.在StackOverflow.在开源码软件中,等等), ...
- 三年程序学习之二:(对web初认识)
接着上一篇讲,之后第二天我就来公司上班了,主要是前端,CSS+DIV,table,网站维护之类的,这样的日子过了将近3个星期,一直没什么进展,自己也学不到什么技术,不过我觉得CSS+DIV我算是基础的 ...
- Hadoop-- MapReduce简单理解
1.Hadoop和MapReduce概念 Mapreduce是一种模式. Hadoop是一种框架. Hadoop是一个实现了mapreduce模式的开源的分布式并行编程框架. 2.Hadoop框架 ...
- BIOS启动项中的设备都有哪些
Floppy 软式磁盘驱动器,简称FDD,也就是我们平时所说的软驱. CD-ROM 不用多说了,大家都知道,这是光盘驱动器,也就是我们平时说得光驱. SCSI SCSI的全名是:Small Compu ...
- 转】Linux下安装Tomcat服务器和部署Web应用
原博文出自于: http://www.cnblogs.com/xdp-gacl/p/4097608.html 感谢! 一.上传Tomcat服务器
- HDU 1525 Euclid's Game (博弈)
Euclid's Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- java 常用concurrent类
1.CountDownLatch 它的作用主要是当多个(数量等于初始化CountDownLatch时count参数的值)线程到达了预期状态或完成预期工作时触发事件,其他线程可以等待这个事件来触发自己后 ...