zoukankan      html  css  js  c++  java
  • 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
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    概率论基础学习笔记
    树点涂色
    2016北京集训测试赛(八)Problem C: 直径
    BZOJ 4361 ISN
    2017省选集训测试赛(二十五)Problem B recollection
    2016北京集训测试赛(六)Problem B: 矩阵
    记录Vue和Jquery混合开发中关于点击事件的一个bug
    记录JQ-WEUI中滚动加载的一个BUG
    Vue Elementui 如何让输入框每次自动聚焦
    什么是CDN加速?(转载)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4662238.html
Copyright © 2011-2022 走看看