2012 ACM/ICPC Asia Regional Tianjin Online

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.

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

Source
貌似昨天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,冲到第一了吼吼。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值