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

对于方程X^Z + Y^Z + XYZ = K,已知K求此方程解的个数,其中要求X<Y,Z>1,而K的范围是0到2^31。

首先我们来分析Z的范围:由于X,Y为正整数,X < Y,则1 < X < Y, =====> Y >= 2

=> X^Z + Y^Z + XYZ > Y^Z

=> 2^Z <= Y^Z < 2^31

所以得到2 <= Z<31

对于Z=2时式子左边可以化为(x+y)^2 = k 的形式。

所以当k 是完全平方数的时候,(x,y) 才有可能有解。

假如m^2 = k ,问题就相当于求x+y = m (x < y) 的解的组数。

容易得出ans=(m-1)/2。

而Z在3<=Z<31的情况。

我们再来分析X的范围:

对于方程X^Z + Y^Z + XYZ = K, X < Y,则有X^Z + Y^Z + XYZ > 2*X^Z + X*X*Z >= 2*X^3 + 3*X^2

即我们得到:2*X^3 + 3*X^2 < 2^31 解这个方程有:X < 1024

于是现在我们得到了3 <= Z < 31,1 <= X < 1024,当然Z=2特殊处理。接下来就直接枚举X,Z,再枚举Y。

复杂度O(10^4)左右,因为y不会和相差太远

#pragma comment(linker, "/STACK:36777216")
#pragma GCC optimize ("O2")
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%I64d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
#define eps 1e-9
const double pi = acos(-1.0);
typedef long long LL;
typedef unsigned long long ULL;
const int modo = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxn = 1005,N = 50000;
LL s,k,ans;
LL f[1300][32];
void init()
{
for(int i = 1; i < 1300;++i){
f[i][0] = 1;
for(int j = 1;j < 32;++j){
f[i][j] = f[i][j-1]*i;
if(f[i][j] > (1LL<<31))
break;
}
}
}
int main(){
init();
while(~RD(k),k){
ans = 0;
s = sqrt(k);
if(s * s == k){
ans += (s - 1)/ 2;
}
for(int x = 1;x < 1024;++x){
for(int z = 3;z < 31;++z){
if(f[x][z] == 0)
break;
for(int y = x + 1;;++y){
if(f[y][z] == 0 || f[x][z] + f[y][z] + x*y*z > k)
break;
else if(f[x][z] + f[y][z] + x*y*z == k){
ans ++ ;
break;
}
}
}
}
printf("%I64d\n",ans);
}
return 0;
}

hdu 4282 枚举,非二分的更多相关文章

  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. Interviewe HDU - 3486 (ST表+枚举 )(非二分,看下这个数据、)

    YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there ...

  3. 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/sh ...

  4. HDU 1407 测试你是否和LTC水平一样高 枚举、二分、hash

    http://acm.hdu.edu.cn/showproblem.php?pid=1407 计算方程x^2+y^2+z^2= num的一个正整数解.num为不大于10000的正整数 思路: 方法一. ...

  5. hdu 3264(枚举+二分+圆的公共面积)

    Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  6. HDU 5726 GCD (RMQ + 二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5726 给你n个数,q个询问,每个询问问你有多少对l r的gcd(a[l] , ... , a[r]) ...

  7. HDU 5289 Assignment(二分+RMQ-ST)

    Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  8. HDU 4768 Flyer(二分)

    题目链接: 传送门 Flyer Time Limit: 1000MS     Memory Limit: 32768 K Description The new semester begins! Di ...

  9. hdu 4770(枚举 + dfs爆搜)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4770 思路:由于最多只有15个".",可以直接枚举放置的位置,然后判断是否能够全部 ...

随机推荐

  1. 在IP网络中,P、PE、CE代表意思

    1.ce , pe属于mpls vpn里的概念.VPN概念中,把整个网络中的路由器分为三类:用户边缘路由器(CE).运营商边缘路由器(PE)和运营商骨干路由器(P):其中,PE充当IP VPN接入路由 ...

  2. MySQL学习笔记-数据库文件

    数据库文件 MySQL主要文件类型有如下几种 参数文件:my.cnf--MySQL实例启动的时候在哪里可以找到数据库文件,并且指定某些初始化参数,这些参数定义了某种内存结构的大小等设置,还介绍了参数类 ...

  3. 担心后端代码泄露?用delphi做后端,模板扣出来,随时可以变化。

    担心后端代码泄露?用delphi做后端,模板扣出来,随时可以变化. 本项目不是intraweb, unigui等类似的拖拉项目,只是一个简单 的模板引擎,理论上可以结合任何后端. 要就下载源码,作者保 ...

  4. Linux 中的文件锁

    参考资料: https://www.ibm.com/developerworks/cn/linux/l-cn-filelock/index.html

  5. ubuntu下为单个网卡配置多个ip

    参考文档: https://www.jb51.net/os/Ubuntu/418951.html https://blog.csdn.net/ying1989920/article/details/4 ...

  6. 编译sgbm_ros中遇到的问题

    出现的问题 这个会报错 1.解决方法是在文件sudo gedit /usr/local/cuda/include/crt/common_functions.h中注释掉如下 #define __CUDA ...

  7. SecureCRT乱码解决

    本文不涉及编码,只说明ssh问题产生的乱码 如果终端中输出以下字符,就会出现乱码 echo -e '\xe' 还有 ctrl+v,ctrl+n也能产生乱码 恢复方法 echo -e '\xf'

  8. 【密码学】轻松理解“加盐”的原理与java实现

    转自:https://blog.csdn.net/DavidHuang2017/article/details/80283469 一.什么是加盐? 1.背景 现在很多公司后台以hash值形式存储用户密 ...

  9. HTML 内 meta标签

    <!-- 是否删除默认的苹果工具栏和菜单栏 --> <meta name="apple-mobile-web-app-capable" content=" ...

  10. 谷歌开源OCR,tesseract-ocr使用笔记

    官方教程地址:https://github.com/tesseract-ocr/tesseract/wiki/Compiling 测试版本为 root@9a2a063f9534:/tesseract/ ...