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/showproblem.php?pid=4282

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

TThere 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

 

题意

给你K,求X^Z+Y^Z+X*Y*Z=K有多少个解

题解

枚举X,Z,二分Y

代码

 

#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int k,maxa;

inline int f(int a,int b,int x)
{
    return pow(x*1.0,b*1.0)+pow(a*1.0,b*1.0)+a*b*x-k;
}

bool judge(int a,int b)
{
    int L,R,M,t;
    L=a+1;R=maxa;
    if(f(a,b,L)>0||f(a,b,R)<0) return false;
    while(L<=R)
    {
        M=(L+R)>>1;
        t=f(a,b,M);
        if(t==0) return true;
        else if(t>0) R=M-1;
        else L=M+1;
    }
    return false;
}

int main()
{
    int ans,a,b;
    while(scanf("%d",&k)==1&&k)
    {
        ans=0;
        for(b=2;b<=30;b++)
        {
            maxa=pow(k*1.0,1.0/b);
            for(a=1;a<=maxa;a++)
            {
                if(judge(a,b))
                    ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

 

 

,

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4282

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

TThere 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

 

题意

给你K,求X^Z+Y^Z+X*Y*Z=K有多少个解

题解

枚举X,Z,二分Y

代码

 

#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int k,maxa;

inline int f(int a,int b,int x)
{
    return pow(x*1.0,b*1.0)+pow(a*1.0,b*1.0)+a*b*x-k;
}

bool judge(int a,int b)
{
    int L,R,M,t;
    L=a+1;R=maxa;
    if(f(a,b,L)>0||f(a,b,R)<0) return false;
    while(L<=R)
    {
        M=(L+R)>>1;
        t=f(a,b,M);
        if(t==0) return true;
        else if(t>0) R=M-1;
        else L=M+1;
    }
    return false;
}

int main()
{
    int ans,a,b;
    while(scanf("%d",&k)==1&&k)
    {
        ans=0;
        for(b=2;b<=30;b++)
        {
            maxa=pow(k*1.0,1.0/b);
            for(a=1;a<=maxa;a++)
            {
                if(judge(a,b))
                    ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

 

 

    原文作者:qscqesze
    原文地址: https://www.cnblogs.com/qscqesze/p/4662238.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞