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.

Input  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  Output the total number of solutions in a line for each test case. 
Sample Input

9
53
6
0

Sample Output

1
1
0

Hint

9 = 1^2 + 2^2 + 1 * 2 * 2
53 = 2^3 + 3^3 + 2 * 3 * 3

题意 给你一个k

解方程 X^Z + Y^Z + XYZ = K   其中x>=1 y>x,z>1 让你解出有多少种解

枚举所有x的可能情况 ,在每个x上z的可能情况枚举,然后用二分求出y,并且判断y是否符合方程。

代码:

/*
1.x 范围为1~sqrt(k/2)  time:1~3w
2.z 范围为2~log2(k);//times:1~30
3.二分求 y  y的范围为(x+1)~pow(k,1/z);times:log(3w);
*/
#include<stdio.h>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#define INF 0x3f3f3f3f
#define N 10010
using namespace std;
typedef long long ll;
//int k,x,z;
ll k;
ll qucikpow(ll a,ll b)
{ll ans=1;while(b){if(b&1)ans*=a;a=a*a;b/=2;}return ans;
}
ll compute(ll x,ll y,ll z)
{ll ans=qucikpow(x,z)+qucikpow(y,z)+x*y*z;return ans;
}
int Slove(ll x,ll z)//根据此时的x z和y的范围找y 并且判断答案是否存在
{ll l=x+1;ll r,mid,ans;r=(ll)pow(k*1.0,1.0/z);while(l<r){mid=(l+r)/2;ans=compute(x,mid,z);if(ans<k)l=mid+1;elser=mid;}if(l!=r)//防止r比l小return 0;ans=compute(x,r,z);if(ans==k)return 1;elsereturn 0;
}
int main()
{int ans;ll lz;ll mid;while(~scanf("%lld",&k)&&k)//优化数据范围{ans=0;lz=log(k*1.0)/log(2.0);for(ll x=1;2*x*x<=k;x++){mid=x*x;   for(ll z=2;mid<k&&z<=lz;z++)//{if(Slove(x,z))ans++;mid*=x;}}printf("%d\n",ans);}return 0;
}

C - A very hard mathematic problem (暴力枚举加二分)相关推荐

  1. 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) 给我们这个等式让我们找出这里面有多少 ...

  2. Uva 201 Squares (暴力 + 枚举)

    [题意] 给出  n*n 的 点 H 横向  V  纵向  (注意)  V  想 I,j  相反 问 边 为1 ,2 , 3 .... n 的  正方向有几个 [思路] n 很小 直接暴力 枚举 枚举 ...

  3. D. Shuffle(cf)暴力枚举 + 组合数学

    原题链接:Problem - 1622D - Codeforces 题目大意:给你一串01串,告诉你长度n和一个数k,这个串中所有1的数量为k的子串,可以把这段子串重新排序.问你最后这个串能有多少种. ...

  4. #644 (Div. 3)F. Spy-string(暴力枚举)

    题目描述 You are given n strings a1,a2,-,an: all of them have the same length m. The strings consist of ...

  5. 寒假集训三(暴力枚举)2020.01.02(11题)

    寒假集训三(暴力枚举)id :521 Problem:A 二倍的问题 Description 给定2到15个不同的正整数,你的任务是计算这些数里面有多少个数对满足:数对中一个数是另一个数的两倍.比如给 ...

  6. Problem : 暴力摩托

    Problem : 暴力摩托 原文 Time Limit: 1 Sec Memory Limit: 128 MB Description N个站,之间连了M条双向的通路!但每条路都规定了一个速度的限制 ...

  7. 3347 菊花链(暴力枚举、哈希表)

    1. 问题描述: 每天,作为她绕农场行走的一部分,奶牛 Bessie 会经过她最喜爱的草地,其中种有 N 朵花(五颜六色的雏菊),编号为 1-N,排列成一行.花 i 有 pi 朵花瓣.作为一名崭露头角 ...

  8. POJ 3174 暴力枚举

    思路: 暴力枚举三个点 判一判 搞定 (x1*y1=x2*y2) x1.y1.x2.y2为他们两两的差 //By SiriusRen #include <cstdio> using nam ...

  9. codeforces数学1600day6[CodeForces - 1029C多区间交+枚举,CodeForces 992C[数学公式推导],CodeForces 992B[质因数分解+暴力枚举]]

    A - Maximal Intersection CodeForces - 1029C 题目大意:就是给你n个区间,这n个区间有公共的区间长度为x,现在叫你从这n个区间中删掉一个使得x最大化. 解题思 ...

  10. 最大字段和 冲出暴力枚举

    这篇解题报告是对我最近一些题的总结,里面的代码都是我解题,优化,再优化的过程的记录,记录了自己对算法的完善与优化思路,还有对编程哲学的理解:do it,do it well. 很感谢孙老师您,让自己可 ...

最新文章

  1. 干货 | 一文总结旋转目标检测全面综述:论文方法与代码
  2. datatables如何把列设置成hidden隐藏域?
  3. 线程同步之生产者-消费者问题
  4. nginx,excel模板下载
  5. c语言生成迷宫算法,[原创]递归随机迷宫生成算法详解
  6. 密码学原理与实践_到底什么是防火墙入侵检测密码学身份认证?如何高效建立网络安全知识体系?...
  7. Golang闭包的典型应用
  8. sql 中 case when 语法
  9. Eclipse中如何让Java类与Servlet产生关联【实现处理请求内容】
  10. ENVI学习总结(六)——图像自动配准
  11. 【新模板推荐】目标军令状、假期通知书…签名确认仪式满满
  12. 离线语音空调插座设计应用案例
  13. aptana+php++插件,aptana插件
  14. tig git的好搭档
  15. 恶意程序利用Linksys路由器漏洞在路由器中传播
  16. 教程:客制化您的输入法
  17. scp 命令简明介绍
  18. 统计假设测验------(四)方差分析(F测验、多重比较原理与方法)
  19. AutomatorX自动化测试工具介绍(Android篇)
  20. 汽车信息安全要求(5)——Secure Boot(安全启动)

热门文章

  1. 读《别闹了,费曼先生》 时的几点想法
  2. 从BIM行业看中国工业软件的困境及出路
  3. 偷窥桌面程序和IE浏览器的密码编辑框
  4. 了解计算机技术的课件,了解计算机课件.ppt
  5. Vue + Spring Boot 项目实战:人事管理系统——完结撒花
  6. 面对性骚扰,Siri Alexa等AI助手如何应对
  7. php 漏洞扫描,Webvulscan:一款基于PHP的漏洞扫描器
  8. extremecomponents相关大全
  9. C++类库Pugixml与rapidxml性能评测
  10. 中柏平板电脑刷linux,中柏平板电脑系统下载与安装教程