hdu4282 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
For each case, there is only one integer K (0 < K < 2^31) in a line.
K = 0 implies the end of input.
Output
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和z,然后再二分找符合的y值。
先打表,可以缩短时间。
注意double类型二分函数的写法与int类型二分函数的写法又和不同。
#include<iostream>
#include<cstdio>
#include<string.h>
#include<math.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
int num[50000][35] = {0};
int n;
bool jud(int x,int z,int miu)
{int l = x+1, r= 45000;while(l<=r){int mid = (l+r)>> 1;if(num[mid][z] <= 0){r = mid-1;continue;}if(pow(mid,z)+x*mid*z > miu){r = mid-1; //here wa 以 2和4 为例 !! 切记!}else if(pow(mid,z)+x*mid*z < miu) {l = mid+1; // wa}else return true;}return false;
}
int main()
{for(int x=1;x<45000;x++){num[x][1] = x;for(int z=2;z<31;z++){num[x][z] = num[x][z-1]* x;if(num[x][z] >= 2e9){break;}}}while(scanf("%d",&n) != EOF){if( n== 0 ) break;int cnt = 0;for(int x=1;x<45000&&x<n;x++){for(int z=2;z<31;z++){if(num[x][z] <= 0 ) break;int miu = n - num[x][z];if(miu <= 0) break;if(jud(x,z,miu)){cnt++;}}}printf("%d\n",cnt);}
}
hdu4282 A very hard mathematic problem相关推荐
- 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) 给我们这个等式让我们找出这里面有多少 ...
- 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 ...
- linux下yum错误:[Errno 14] problem making ssl connection Trying other mirror.
所有的base 都要取消注释 mirrorlist 加上注释 另外所有的enable都要设为零 目录 今天是要yum命令安装EPEL仓库后 yum install epel-release 突然发现y ...
- A + B Problem
1001: A + B Problem Description 计算 A + B. Input 多组测试数据,每组测试数据占一行,包括2个整数. Output 在一行中输出结果. Sample Inp ...
- Error:(49, 1) A problem occurred evaluating project ':guideview'. Could not read script 'https://r
出现问题如下: Error:(49, 1) A problem occurred evaluating project ':guideview'. > Could not read script ...
- #418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)
题目链接:http://codeforces.com/contest/814/problem/B 题意 : 有一个给出两个含有 n 个数的序列 a 和 b, 这两个序列和(1~n)的其中一个全排列序列 ...
- ADPRL - 近似动态规划和强化学习 - Note 3 - Stochastic Infinite Horizon Problem
Stochastic Infinite Horizon Problem 3.Stochastic Infinite Horizon Problem 定义3.1 无限范围的马尔可夫决策过程 (Marko ...
- ADPRL - 近似动态规划和强化学习 - Note 2 - Stochastic Finite Horizon Problem
2. Stochastic Finite Horizon Problem 在这一节中主要介绍了随机DP算法来解决不确定性下的有限地范围问题,如Denition 1.4所述,它被表述为一个组合优化问题. ...
- There was a problem confirming the ssl certificate ……
在安装一个Python库onetimepass时发生下面的问题: pip install onetimepass Could not fetch URL https://pypi.python.org ...
- HDU 1757 A Simple Math Problem
Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x & ...
最新文章
- opencv机器学习线性回归_全面讲解手推实战机器学习之线性回归
- ecmobile实现支付宝支付和百度云推送遇到的问题及解决方案(android)
- pat1043. Is It a Binary Search Tree (25)
- 全国计算机等级考试题库二级C操作题100套(第19套)
- 【洛谷习题】尼克的任务
- SVN仓库安装、备份和迁移基本操作
- 前端demo - 点名器
- 后台管理导航菜单及模板
- 纯前端导出excel文件(包含设置样式)
- html5怎么修改图片大小,HTML5 javascript修改canvas的大小
- 南京考公上岸经验分享
- Windows实现微信双(多)开—微信分身
- 电视为何降价至200元依然没人买?爱奇艺给出了答案
- 夯实第一超市地位 京东超市成超10大品类超50家品牌线上最大渠道
- 诺基亚发布NetAct云网络管理系统,为5G网络演进铺路
- qdbus模块_PyQt 学习笔记4——库结构
- Empfehlung für Artikel „Joyn Video Download: Empfehlung vom besten Joyn Downloader“
- Excel排名函数PERCENTRANK计算逻辑
- P26-P34 third_template
- erpnext v13 安装部署 + VSCode本地开发环境配置
热门文章
- 从源程序到可执行文件的四个过程
- A69G-HDMI问题解决集锦
- php小h站视频系统源码,苹果cms v10x 原创自适应x站h站源码 视频模板 带试看功能 带自动采集YM源码...
- python123高次方程求根_GitHub - loveunk/math-advanced-algebra-notes: 根据丘维声的《高等代数》整理...
- 谈谈创业这点事(4)
- php递归函数的用法,PHP递归函数用法
- 获取JSON文本(复嵌对象)转换指定JSON数据并Ajax实现数据初始可视化【附上echarts地图官方数据形式json文件数据】
- 省市区联动附(2020年省市区数据)
- ROS教程之读取激光雷达(sick_tim561)数据
- Oracle LiveLabs实验:Introduction to Oracle Spatial