zoukankan      html  css  js  c++  java
  • A Cubic number and A Cubic Number (二分) HDU

    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 <iostream>
    #include <algorithm>
    #include <iomanip>
    #include <stdio.h>
    #include <set>
    #include <cstdio>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <map>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <cstring>
    #include <sstream>
    #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<<a[i-1]<<" ";
        }
        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<<" +++ "<<l<<" "<<r<<endl;
            }
            if(!flag) cout<<"NO"<<endl;
            else cout<<"YES"<<endl;
        }
    
    }
    所遇皆星河
  • 相关阅读:
    java.lang.NoSuchMethodError: org.springframework.web.context.request.ServletRequestAttributes.<init>
    eclipse web项目实际工程路径对应
    java中专业术语详解
    Maven详解
    工作常用
    html页面布局
    jQuery易混淆概念的区别
    Jquery Datagrid
    Jquery EasyUI 动态添加标签页(Tabs)
    sql语句的写法
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11709049.html
Copyright © 2011-2022 走看看