2012 ACM/ICPC Asia Regional Tianjin Online
来源:互联网 发布:wamp配置虚拟域名 编辑:程序博客网 时间:2024/05/18 01:23
A very hard mathematic problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1455 Accepted Submission(s): 440
Problem Description
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.
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.
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
95360
Sample Output
110Hint9 = 1^2 + 2^2 + 1 * 2 * 253 = 2^3 + 3^3 + 2 * 3 * 3
Source
2012 ACM/ICPC Asia Regional Tianjin Online
貌似昨天rp都用光了,今天上来A题秒过n多人,压力山大,然后看到上面那倒,一看就是二分查找的感觉,但是输入2^31,电脑就卡了不给输出,开始还以为难道超时了,难道还有什么高深莫测的优化,无奈放下,刚看到最后一题简单想做来着,不知道我们那个账号有的人这么多尽然a了,简单的都被A完了我干嘛Y-Y......然后看到这道题过的人越来越多,果断再来debug,一个一个数据输到104800,还有输出,到104900,瞬间卡屏,不至于瞬间超时,然后终于想通了,数据溢出了(Y-Y),虽然k《=2^31;二分计算函数值的时候会超过的啊Y-Y,终于闷骚的打了一瓶酱油过了,昨天过一道,今天还是一道Y——Y,下次来个突破吧,阿弥陀佛善哉善哉
#include<string.h>#include<stdio.h>#include<math.h>long long y,z,k,sum,f,ok[1290];long long fx(long long a,long long b,long long c){ long long i,aa=1,bb=1; for (i=1;i<=c;i++) { aa=aa*a;//本来用pow,记得好像是计算实数会不会有精度误差不用算了- bb=bb*b; } return aa+bb+a*b*c;}void find(long long l,long long r){ long long m=(l+r)/2,key; key=fx(m,y,z); if (key==k) {if (m>0&&m<y) f=1; return ;} if (l>=r) return; if (key<k) find(m+1,r); else find(l,m-1);}int main(){ long long t,exp=0; while (scanf("%lld",&k),k) { sum=0; t=sqrt(k); if (t*t==k)//z=2,直接开方, { if (t%2==1) sum=t/2; else sum=t/2-1; } for (z=3;fx(1,2,z)-exp<=k;z++) { y=2; while (fx(1,y,z)-exp<=k)//说起exp,是为了调试程序用的看边界条件,其实边界开始就对的最后exp=0,可有可无 { f=0; find(1,y-1); sum=sum+f; ++y; } } printf("%lld\n",sum); } return 0;}最后再去hdu用gcc跑了下15ms,再用c跑了下0ms,冲到第一了吼吼。
- 2012 ACM/ICPC Asia Regional Tianjin Online
- 2012 ACM/ICPC Asia Regional Tianjin Online [赛后解题报告]
- 2012 ACM/ICPC Asia Regional Tianjin Online-Faulty Odometer
- 2012 ACM/ICPC Asia Regional Tianjin Online [赛后解题报告]
- 2012 ACM/ICPC Asia Regional Tianjin Online 1006_you are the one 解题报告
- 2012 ACM/ICPC Asia Regional Tianjin Online ——A very hard mathematic problem解题报告
- HDU4280 Island Transport(2012 ACM/ICPC Asia Regional Tianjin Online)
- hdu 4283 You Are the One (2012 ACM/ICPC Asia Regional Tianjin Online 1006 )
- 2012 ACM/ICPC Asia Regional Tianjin Online hdu 4287 map和char[]的合作应用
- 2012 ACM/ICPC Asia Regional Tianjin 1010 Intelligent IME
- 2012 ACM/ICPC Asia Regional Changchun Online
- 2012 ACM/ICPC Asia Regional Jinhua Online
- The 35th ACM/ICPC Asia Regional Tianjin Site —— Online Contest
- HDU3622 Bomb Game(2-SAT 问题,The 35th ACM/ICPC Asia Regional Tianjin ,Online)
- The 37th ACM/ICPC Asia Regional Tianjin Site Online Contest - A.B.J
- The 37th ACM/ICPC Asia Regional Tianjin Site Online Contest - A.B.J
- The 37th ACM/ICPC Asia Regional Tianjin Site Online Contest - G Travel
- 2012 ACM/ICPC Asia Regional Online Warmup-1003
- SVN 常用命令总结
- jquery实现搜索框自动补全功能,类似google搜索引擎,数据是用Ajax从后台获得
- 用python爬虫抓站的一些技巧总结
- Android深入浅出之Surface[1]
- 微软、google、雅虎、百度等各大著名公司的经典面试题
- 2012 ACM/ICPC Asia Regional Tianjin Online
- QML与C++混合编程使用
- C++与C#对比学习:多态,虚函数
- MSSQL创建“全文索引”
- 一个优秀程序员的成功之道:15个不可忽视的编程好习惯!!~
- 在linux中显示所有正在运行的进程
- 二十世纪最伟大的十大算法!!数学软件计算机必看!~
- 尕福(散文)
- 目前使用SAP的公司列表