A very hard mathematic problem

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4282

Description

 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

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

9 53 6 0

Sample Output

1 1 0

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 二分的更多相关文章

  1. 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) ...

  2. hdu 4282 A very hard mathematic problem

    由于k的范围是0-2^31,而且x,y,z都是正整数,由题易知道2<=z<31,1<=x<y;所以直接枚举就好了!!! #include<iostream> #in ...

  3. hdu 4972 A simple dynamic programming problem(高效)

    pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic progra ...

  4. HDU 2254 奥运(矩阵高速幂+二分等比序列求和)

    HDU 2254 奥运(矩阵高速幂+二分等比序列求和) ACM 题目地址:HDU 2254 奥运 题意:  中问题不解释. 分析:  依据floyd的算法,矩阵的k次方表示这个矩阵走了k步.  所以k ...

  5. 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 ...

  6. hdu 4282 枚举,非二分

    http://acm.hdu.edu.cn/showproblem.php?pid=4282 对于方程X^Z + Y^Z + XYZ = K,已知K求此方程解的个数,其中要求X<Y,Z>1 ...

  7. HDU 2141 Can you find it? (二分)

    题目链接: Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/ ...

  8. HDU 2236:无题II(二分搜索+二分匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2236 题意:中文题意. 思路:先找出最大和最小值,然后二分差值,对于每一个差值从下界开始枚举判断能不能二分匹配. ...

  9. hdu 1839 Delay Constrained Maximum Capacity Path 二分/最短路

    Delay Constrained Maximum Capacity Path Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu. ...

随机推荐

  1. DevExpress 14.2.3源码编译 z

    一.准备 1.准备一台Windows 8.1机器,安装VS2013 2.准备一台Windows 8.1机器,安装VS2010    XP的系统肯定不行,因为有不少的运行库不支持     Windows ...

  2. LoadRunner--内存指标介绍

    Threads——线程数当前全部线程数============================================ Available MBytes——物理内存的可用数指计算机上可用于运行 ...

  3. jQuery需要掌握的技巧

    检查 jQuery 是否加载 在使用 jQuery 进行任何操作之前,你需要先确认它已经加载: if (typeof jQuery == 'undefined') { console.log('jQu ...

  4. Epic - Snake Sequence

    You are given a grid of numbers. A snakes equence is made up of adjacent numbers such that for each ...

  5. hadoop的kerberos认证

    言归正传,介绍过hadoop的simple认证和kerberos后,我们在这一章介绍hadoop的kerberos认证 我们还使用hadoop集群的机器. OS 版本: Centos6.4 Kerbe ...

  6. Java Web高性能开发(二)

    今日要闻: 性价比是个骗局: 对某个产品学上三五天个把月,然后就要花最少的钱买最多最好的东西占最大的便宜. 感谢万能的互联网,他顺利得手,顺便享受了智商上的无上满足以及居高临下的优越感--你们一千块买 ...

  7. CentOS6.5修改mysql数据文件路径

    1.停止mysql服务      service mysql stop 2.移动数据文件位置(保留原文件权限)      cp -a /var/lib/mysql /mysqldata 3.修改/et ...

  8. datagrid url json

    <div class="easyui-accordion" style="width:500px;height:300px;"> <div t ...

  9. POJ1185状态压缩DP

    难得的中文题. POJ1185http://poj.org/problem?id=1185 方法就是用DP[i][r][p]表示第i行状态为r,第i-1行状态是p时的最多个数.而这里p受到r的限制,而 ...

  10. LRESULT与wParam和lParam的问题

    在微软vc提供的头文件中有定义在winnt.h中typedef long LONG;在windef.h中typedef LONG LRESULT; 所以LRESULT就是long,也就是长整形之所以取 ...