HDU 4282A very hard mathematic problem(二分)

来源:互联网 发布:eia数据公布 编辑:程序博客网 时间:2024/05/16 07:01

题意: 找出符合公式条件的个数

思路:  暴力枚举z, 二分对于当前的x  , y的可能是否存在

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>typedef long long ll;using namespace std;ll pow2(ll a, ll b){    ll k = 1;    for(ll i=1; i<=b; ++i)        k *= a;    return k;}int main (void){    ios::sync_with_stdio(false);    ll k;    while(cin>>k, k)    {        ll ans = 0;        for(ll z=2; z<=32; ++z)        {            ll ed = pow(2147483647/2, 1.0/z) + 0.5;            for(ll x=1; x<=ed; ++x)            {                ll l = x+1, r = ed*2, mid;                while(l <= r)                {                    mid = (l+r) >> 1;                    if(pow2(x, z) + pow2(mid, z) + x*mid*z == k)                    {                        ans ++ ;                        break;                    }                    else if(pow2(x, z) + pow2(mid, z) + x*mid*z < k)                        l = mid+1;                    else                        r = mid-1;                }            }        }        cout<<ans<<endl;    }    return 0;}


阅读全文
0 0
原创粉丝点击