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. gcd(欧几里得算法)

    基础 int gcd(int a,int b)   {       int r;       )       {            r=a%b;            a=b;           ...

  2. VS2010正则批量替换set_和get_

    批量替换set_: daohang.set_ChannelName(rowArray[0]["ChannelName"].ToString()); daohang.set_Chan ...

  3. libnet 库使用(一)

    该库的相关资料主要从源码包中获得(假设当前路径为源码包路径): ./sample 中有代码示例 ./doc/html    中html文件可以通过浏览器打开,参看函数定义 想要的基本上sample中都 ...

  4. Arithmetic Slices II - Subsequence LT446

    446. Arithmetic Slices II - Subsequence Hard A sequence of numbers is called arithmetic if it consis ...

  5. 使用mysql proxy对数据库进行读写分离

    服务器安排如下: 192.168.100.128 主 192.168.100.129 从 192.168.100.130 mysql-proxy 1.在100.130中下载安装mysql-proxy ...

  6. 添加/删除-HTML DOM 常用对象 -BOM-打开和关闭窗口- history-location

    1. 添加/删除 3步: 1. 添加一个空元素 var a=document.createElement("a"); <a></a> 2. 定义元素的关键属 ...

  7. codeforces C. Functions again

    题意:给定了一个公式,让你找到一对(l,r),求解出公式给定的F值. 当时没有想到,我把(-1)^(i-l)看成(-1)^i,然后思路就完全错了.其实这道题是个简单的dp+最长连续子序列. O(n)求 ...

  8. python学习 day4 (3月5日)---列表

    列表: 容器性数据 有序  可更改 大量数据 一.增 1.追加    append(objcet) 2.索引增加   Insert(index,元素) 3.迭代追加   extend(object) ...

  9. IDEA导入MySQL包

    点击[Project Structure] 点击[Modules]   在点击下面的界面   找到自己下载的MySQL包就OK了  

  10. 【转】CentOS 7 安装配置 NFS

    环境 nps 192.168.1.97 client 192.168.1.98 一.yum 安装 yum -y install nfs-utils rpcbind nfs 的配置文件 /etc/exp ...