HDU 6216 A Cubic number and A Cubic Number

来源:互联网 发布:变压器温升计算软件 编辑:程序博客网 时间:2024/05/30 23:21

题目链接:HDU 6216

A Cubic number and A Cubic Number

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 174    Accepted Submission(s): 109


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

Input
The first of input contains an integer T (1T100) which is the total number of test cases.
For each test case, a line contains a prime number p (2p1012).
 

Output
For each test case, output 'YES' if given p is a difference of two cubic numbers, or 'NO' if not.
 

Sample Input
102357111317192329
 

Sample Output
NONONOYESNONONOYESNONO
 

Source
2017 ACM/ICPC Asia Regional Qingdao Online 
 
题意:给一个质数,问是否是2个立方数的差。
题目分析:太搞笑了这题我们(-3)(内心mmp),,,立方差公式展开发现x和y差1,然后最多就1e6种情况,然后打表查询,然后就没有然后了。
我们WA-2,CE-1

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;ll s[1111111];void init(){    for(ll i=1;i<=1e6;i++)    {        s[i]=i*i*3+3*i+1LL;    }}int T,n;int main(){    init();    scanf("%d",&T);    while(T--)    {        ll n;        cin>>n;        int flag=0;        for(int i=1;i<=1e6;i++)        {            if(s[i]>=1e12) break;            if(s[i]>n) break;            if(s[i]==n)            {                flag=1;                break;            }        }        if(flag==1) printf("YES\n");        else printf("NO\n");    }}


原创粉丝点击