A very hard mathematic problem HDU - 4282
A very hard mathematic problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7411 Accepted Submission(s): 2232
Problem 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
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
Source
2012 ACM/ICPC Asia Regional Tianjin Online
Recommend
liuyiding
1.枚举+快速幂
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define maxx 1e9
using namespace std;
typedef long long ll;
ll powmod(ll a, ll b)//快速幂
{ll ans = 1;while(b){if(b%2==1)ans = (ans * a);b=b/2;a = (a*a);}return ans;
}
int main()
{int i,j;int k;int z;while(cin>>k, k){int ans = 0;ll tx,ty;ll tk = (int)sqrt(k*1.0);if(tk*tk == k)ans += (tk-1)/2;for(z=3; z<31; z++){for(ll x=1; ; x++){ll tx = powmod(x,z);if(tx >= k/2) break;for(ll y=x+1; ; y++){ll ty = powmod(y, z);if( tx + ty + x*y*z > k) break;else if(tx + ty + x*y*z == k){ans++;break;}}}}printf("%d\n", ans);}return 0;
}
2.暴搜+二分
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define maxx 1e9
using namespace std;
typedef long long ll;
ll powmod(ll a, ll b)
{ll ans = 1;while(b){if(b%2==1)ans = (ans * a);b=b/2;a = (a*a);}return ans;
}
int main()
{int i,j;int k;int z;while(cin>>k, k){int ans = 0;ll tx,ty;ll lt,rt;ll tk = (int)sqrt(k*1.0);if(tk*tk == k)ans += (tk-1)/2;for(z=3; z<31; z++){for(ll y=2; ;y++){ty = powmod(y, z);if(ty > k) break;lt =1; rt=y-1;while(lt<=rt){ll x= (lt+rt)/2;ll ta=pow(x, z) + pow(y, z) + x*y*z;if(ta < k){lt++;}else if(ta > k){rt--;}else{ans++;break;}}}}printf("%d\n", ans);}return 0;
}
A very hard mathematic problem HDU - 4282相关推荐
- 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 ...
- A Simple Math Problem HDU - 5974
Given two positive integers a and b,find suitable X and Y to meet the conditions:X+Y=aLeast Common M ...
- 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) 给我们这个等式让我们找出这里面有多少 ...
- bitset HDU6515 Coding Problem
Coding Problem [ HDU - 6515 ] 题目大意:给你一个字符串,每个字母的ASCII二级制颠倒过来组成一个01数组. 然后这个数组每六位组成一个数字的ASCII输出 一道模拟题, ...
- [HDU 3625] Examining the Rooms(第一类斯特林数)
Examining the Rooms problem solution code problem hdu 3625 solution 之前考试有一道题:最多砸开 kkk 扇门,采取最有操作,求把 n ...
- HDU 1033 水题
题意还真的不好懂,摸索数据就出来了,注意顺时针和逆时针时候的方向变化 /* * Author:lonelycatcher * problem:hdu 1033 * Type:水题 */ #in ...
- HDU 1027 全排列
这是一道排列的题目,北大的程序设计书里面有这道题,讲的挺细的,可以去看看,两种方法 /* * Author:lonelycatcher * Problem:HDU 1027 * Type:全排列 ...
- hdu 1493 qq宠物
hdu 1493 QQpet exploratory park 概率dp 题目网址: http://icpc.njust.edu.cn/Problem/Hdu/1493/ 本来以为很简单,结果硬是坑了 ...
- hdu 4664 Triangulation
// 题意: 给定N个平面,每个平面有ni个点 // ni个点组成一个凸多边形 // // 然后在N个平面上进行游戏,每次选取一个平面进行 // 在每个平面上可以选择两个点链接一条直线 // 每次选择 ...
- HDU 1530 Maximum Clique 最大团
题意:给一个图,找图中的最大团,并输出最大团的顶点数. 思路:暴搜.dfs判断每个点在或者不在.加一个剪枝.就是如果剩下的节点+当前已经搜到的最大团的节点<=已经找到的最好结果,就停止搜索.这个 ...
最新文章
- 【Ionic+AngularJS 开发】之『个人日常管理』App(二)
- python基础课程多少钱-培训python多少钱 ?
- 前端- jquery- 总结
- react 组件遍历】_从 Context 源码实现谈 React 性能优化
- python取反函数_Python优雅的反函数int(string,base)
- Tensorflow 2.0的新特性
- Remoting系列专题---自定义序列化类
- IPv4数据报格式及其语义
- 【软件测试】黑盒测试の等价类划分法
- C++:求第k小的数
- 452. 用最少数量的箭引爆气球(JavaScript)
- Selenium自动化测试-3.元素定位(3)
- 算法_深度LSTM笔记[博]
- poj 2506 Tiling dp 递推
- 计算机毕业设计Java校园一卡通管理系统(源码+系统+mysql数据库+Lw文档)
- STM32单片机+proteus8仿真的简易交通灯设计
- HDMI调试基本原理
- html网页设计板报,html5做一个黑板报页面
- web语意化的深入理解
- C. Neko does Maths
热门文章
- 拟合美国人口matlab编码,美国人口数据的阻滞增长模型拟合分析
- c#图解教程和c#高级编程电子书链接
- Spring-boot-2.1.X源码编译
- Win11软件兼容性怎么样?
- 小组作业:学生信息管理系统需求分析
- 玩转 SSH(六):SpringMVC + MyBatis 架构搭建(注解版)
- SQL Server 2017安装错误:Polybase要求安装Oracle JRE 7更新51或更高版本的两种解决方法
- 【封包技巧】利用wpe来(判断是否是某个特征码封包字节,然后进程修改)
- 五笔字根表识别码图_王码86版五笔字根表口诀助记词(完整大图)
- java gc什么意思_对Java GC的简单理解