hdu 4282 枚举,非二分
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 枚举,非二分的更多相关文章
- 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) ...
- Interviewe HDU - 3486 (ST表+枚举 )(非二分,看下这个数据、)
YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there ...
- 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 ...
- HDU 1407 测试你是否和LTC水平一样高 枚举、二分、hash
http://acm.hdu.edu.cn/showproblem.php?pid=1407 计算方程x^2+y^2+z^2= num的一个正整数解.num为不大于10000的正整数 思路: 方法一. ...
- hdu 3264(枚举+二分+圆的公共面积)
Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDU 5726 GCD (RMQ + 二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5726 给你n个数,q个询问,每个询问问你有多少对l r的gcd(a[l] , ... , a[r]) ...
- HDU 5289 Assignment(二分+RMQ-ST)
Assignment Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- HDU 4768 Flyer(二分)
题目链接: 传送门 Flyer Time Limit: 1000MS Memory Limit: 32768 K Description The new semester begins! Di ...
- hdu 4770(枚举 + dfs爆搜)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4770 思路:由于最多只有15个".",可以直接枚举放置的位置,然后判断是否能够全部 ...
随机推荐
- 使用/\_ 打印正三角形 C/C++
输入size,level,使用/\_,打印正三角形 #include<stdio.h> int main() { int level, size; printf("Enter l ...
- PAT 甲级 1011 World Cup Betting (20)(代码+思路)
1011 World Cup Betting (20)(20 分) With the 2010 FIFA World Cup running, football fans the world over ...
- andorid 练习微信登陆
AndroidManifest.xml layout1.xml <?xml version="1.0" encoding="utf-8"?> < ...
- hdu 3415(单调队列) Max Sum of Max-K-sub-sequence
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=3415 大意是给出一个有n个数字的环状序列,让你求一个和最大的连续子序列.这个连续子序列的长度小于等于k. ...
- 关于ip包长度
http://blog.csdn.net/naturebe/article/details/6712153 这篇文章总结的不错,转自:http://hi.baidu.com/to_wait/blog/ ...
- NOI导刊 2018河南郑州游记
前言 本蒟蒻来自浙江的弱市弱校,因为不想两年\(OI\)一场空,以及想出去玩,所以与同届大佬一起报了\(NOI\)导刊,希望能留下点不错的记忆吧. \(Day\ 0\) \(10\)月\(1\)日 经 ...
- CURLOPT_HEADER
curl_setopt($curl, CURLOPT_HEADER, false); true:输出请求头
- 用visual studio 2017来调试python
https://www.visualstudio.com/zh-hans/thank-you-downloading-visual-studio/?sku=Professional&rel=1 ...
- 深入理解python里面类的对象的赋值
class T(): def __init__(self): self.name= pass a=T() a.name= b=a #深入理解类,类里面的对象的赋值是指针赋值,也就是同时变的 b.nam ...
- Oracal 学习之用户角色创建分配表空间 给角色分配权限
//创建角色inspur 密码为inspur,默认的表空间为USERS create user inspur identified by inspur default tablespace USERS ...