HDU - 4282 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.
输入说明:
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 the total number of solutions in a line for each test case.
SAMPLE INPUT:
9
53
6
0
SAMPLEOUTPUT:
1
1
0
Hints:
9 = 1^2 + 2^2 + 1 * 2 * 2
53 = 2^3 + 3^3 + 2 * 3 * 3
思路:
题目的要求是让我们解一个方程,并求出一共有多少组解,输出解的数量。
乍一看很难想到怎么用二分去做,仔细想一下,我们可以发现一共有3个未知数,显然,如果对他们都进行二分或者三分是不现实的,所以我们选择枚举x和z,二分搜索合适的y值。此外还有一些需要注意的点,一是z 的取值范围,z是作为上标出现的,其最大值是有限制的(小于32)二是在乘方运算时需要使用快速幂,否则无论时循环求解还是pow求解,时间复杂度都比较高,会tle,因此要使用快速幂的方法。
AC代码:
#include <bits/stdc++.h>
using namespace std;
long long pow(long long a,long long n)
{long long sum=1;long long temp=a;while(n){if(n&1)sum*=temp;temp*=temp;n>>=1;}return sum;
}
int main()
{long long k;long long ans;while(scanf("%d",&k)&&k){ans=0;long long temp=(long long)sqrt(k);if(temp*temp==k)ans+=(temp-1)/2;for(long long z=3;z<31;z++){for(long long x=1;;x++){long long u=pow(x,z);if(u*2>=k)break;for(long long y=x+1;;y++){long long v=pow(y,z);if(u+v+x*y*z>k)break;if(u+v+x*y*z==k)ans++;}}}cout<<ans<<endl;}return 0;
}
HDU - 4282 A very hard mathematic problem相关推荐
- 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 ...
- hdu 2058 解题报告 - The sum problem
hdu 2058 解题报告 - The sum problem 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2058 等差求和公式: Sn=(a1+aN ...
- hdu 3509 Buge's Fibonacci Number Problem(矩阵乘法+二项式)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3509 Buge's Fibonacci Number Problem Time Limit: 10000/ ...
- HDU 6833 A Very Easy Math Problem
A Very Easy Math Problem 推式子 ∑ai=1n∑a2=1n⋯∑ax=1n(∏j=1xajk)f(gcd(a1,a2,-,ax))×gcd(a1,a2,-,ax)\sum_{a_ ...
- HDU 4403 A very hard Aoshu problem DFS
problem statement 这道题给我们一个不超过15位的整数 让我们在其中加等号或者加号 如果加完符号后符合计算结果 那么计数 最后输出所有的情况 problem analysis 这道题其 ...
- 【HDU - 1757】A Simple Math Problem (矩阵快速幂)
题干: Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 f(x) = ...
- hdu 3509 Buge's Fibonacci Number Problem
点击此处即可传送 hdu 3509 题目大意:F1 = f1, F2 = f2;; F(n) = a*F(n-1) + b*F(n-2); S(n) = F1^k + F2^k +-.+Fn^k; 求 ...
- HDU多校4 - 6813 Last Problem(构造)
题目链接:点击查看 题目大意:给出一个无限大的二维平面,需要在平面内进行染色,每次可以选择一个点 ( x , y ) 将其染色为 n 的前提是,相邻四个格子必须分别已经染了 n - 1 , n - 2 ...
- 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 1757【A Simple Math Problem】
矩阵相乘 代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 struct matrix 5 { 6 int g[10][10 ...
最新文章
- runtime 任意类型 model 数据库方便存储
- 全国第九大电商平台倒了!创始人卷走260亿,1200万人被骗
- java冒泡排序_Java冒泡排序,鸡尾酒排序
- “写画”与“惊春”:王艾画展和当代诗人朗诵会
- c#基础知识梳理(四)
- CentOS 7.0 yum安装Apache、PHP和MySQL
- Bootstrap研究2-布局系统杂记
- 今日头条收购锤子?ofo 半月退 24 万户押金;斗鱼索赔主播 1.5 亿元 | 极客头条...
- C#也能PS图片,还能为网站Ajax上传图片同时生成微缩图(附Demo)
- spring 常用注解汇总
- Docker操作命令——查看、停止、删除容器
- 生于凛冬的私募资产配置基金管理人能否秽土转生?
- java 装饰者模式 替代方案_如何利用装饰者模式在不改变原有对象的基础上扩展功能...
- oppor829t如何刷机_OPPO R829T卡刷刷机图文教程
- flutter安装教程与XD教程
- 公有云-主流公有云介绍
- 最新北京人才公寓申请流程,技术员的福利~
- linux ftw()函数使用方法 实例
- Mina中的多项式承诺方案
- 【iOS开发】从小白到低水平开发者进厂实习自救指南
热门文章
- 郭天祥的10天学会51单片机_第十一节
- 12864液晶中文资料JHD529m1
- 单片机外文参考文献期刊_求有关单片机的中英文参考文献
- python3做答题器_现在很火的答题赢钱游戏,让我来简单教你怎么做自动答题器...
- 微型计算机控制技术小论文,微型计算机控制技术结课论文..doc
- 2018Android面试宝典
- Linux下更新BIOS的方法
- linux ftp服务器登录异常解决
- HTML5期末大作业:家乡网站设计——我的家乡-获奖第二(6页) HTML+CSS+JavaScript 关于我的家乡HTML网页设计--
- 若干小球碰撞的一种暴力解题法