A Cubic number and A Cubic Number (二分) HDU - 6216

A cubic number is the result of using a whole number in a multiplication three times. For example,  3×3×3=273×3×3=27 so 2727 is a cubic number. The first few cubic numbers are 1,8,27,641,8,27,64 and 125125. Given an prime number pp. Check that if pp is a difference of two cubic numbers.

InputThe first of input contains an integer T (1T100)T (1≤T≤100) which is the total number of test cases.
For each test case, a line contains a prime number p (2p1012)p (2≤p≤1012).
OutputFor each test case, output 'YES' if given pp is a difference of two cubic numbers, or 'NO' if not.Sample Input

10
2
3
5
7
11
13
17
19
23
29

Sample Output

NO
NO
NO
YES
NO
NO
NO
YES
NO
NO


#include 
#include 
#include 
#include 
#include <set>
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include <string>
#include 
#include 
#define ll long long
const double pi= acos(-1.0);
const double eps = 1e-7;
using namespace std;
ll t,n,k,r,l,m,x;
ll a[1000000];
int main()
{
    for(long long i=2;i<=1000000;i++)
    {
        a[i-1] = (i-1)*(i-1)+i*(i-1)+i*i;
        //if(i<=100) cout<
    }
    int t;
    cin>>t;
    while(t--)
    {
        cin>>k;
        int flag = 0;
        l = 1;r = 1000000;
        while(l<r)
        {
            ll mid = (l+r)/2;
            if(a[mid]>k)
                r = mid;
            else if(a[mid]<k)
                l = mid+1 ;
            else
            {flag = 1 ; break; }
            //cout<<" +++ "<
        }
        if(!flag) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }

}

 

你可能感兴趣的:(A Cubic number and A Cubic Number (二分) HDU - 6216)