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. Linux CentOS 7 & JDK 1.7 安装与配置

    前言 简单记录一下在CentOS 7中安装配置JDK 1.7的全过程~ 下载 首先是jdk 1.7 64bit & 32bit的下载地址: jdk-7u79-linux-x64.tar.gz ...

  2. 希尔排序和归并排序(java实现)

    希尔排序 希尔排序算法实际上是一种特殊的插入排序,由DL.Shell于1959年提出而得名. 算法思想:希尔排序使数组中任意间隔为h的元素都是有序的,这些数组称为h有序数组,对于每个h,按插入排序进行 ...

  3. centos vncviewer

    CentOS6.5 安装vncserver实现图形化访问   一. 安装gnome图形化桌面 #yum groupinstall -y "X Window System" #yum ...

  4. HDU_2136

    #include <iostream> #include <stdio.h> #include <math.h> #include <algorithm> ...

  5. SoftwareEngineering.APIDesign.iOS

    API Design for iOS/Mac (Objective-c Edition) 1. UI Control Library API的设计 和已有组件保持一致(例如: 使用标准的API, 模型 ...

  6. Business.Startup.Learning from Startup Mistakes at SpringSource

    http://www.infoq.com/news/2014/07/startup-spring

  7. 探索未知种族之osg类生物---器官初始化二

    那我们回到ViewerBase::frame函数中来,继续看看为什么osg生命刚刚出生的时候会大哭,除了初始化了eventQuene和cameraManipulator之外还对那些器官进行了初始化.在 ...

  8. 52ABP视频学习

    https://study.163.com/course/courseMain.htm?courseId=1005208064 网易视频 https://www.52abp.com/ReadWiki/ ...

  9. mybatis 一次执行多条语句

    现在的一些互联网应用 为了提高性能,现在一般比较少的使用外键.不是不用,只是在创建数据库不标明外键关系,用程序去维护. 为了维护数据一致性,我们需要手动完成相关数据的删除 比如用户和用户的关注 当用户 ...

  10. MMS从Contacts中添加收件人显示email账号

    android系统默认代码,MMS中可以添加email地址作为收件人,但是从Contacts中选择收件人时却不显示email. 解决思路:为了降低修改量,在原来只搜索phoneNum的基础上,再做一次 ...