A Cubic number and A Cubic Number
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2572 Accepted Submission(s): 1050

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 (1≤T≤100) which is the total number of test cases.
For each test case, a line contains a prime number p (2≤p≤1012).

Output
For each test case, output ‘YES’ if given p 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

Source
2017 ACM/ICPC Asia Regional Qingdao Online

Recommend
liuyiding | We have carefully selected several similar problems for you: 6447 6446 6445 6444 6443

【分析】
题意:给出一个素数p,问p是否是两个立方数的差。
那么设存在整数a,b使得 HDU—6216 A Cubic number and A Cubic Number_#include
化简得HDU—6216 A Cubic number and A Cubic Number_#include_02
因为p是素数,所以p应该只有两个因子1和p本身,那么显然HDU—6216 A Cubic number and A Cubic Number_解方程_03 , HDU—6216 A Cubic number and A Cubic Number_解方程_04
所以可以证明a,b相差1,即HDU—6216 A Cubic number and A Cubic Number_java_05,代入得到HDU—6216 A Cubic number and A Cubic Number_#include_06
然后就是解方程的事情了,只要能解出一个整数解就表示存在两个立方数之差等于p
【代码】

#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main (){
int pp;scanf("%d",&pp);
while (pp--){
long long n;scanf("%lld",&n);
long long delta = 9 + 4 * 3 * (n - 1);
long long sq = sqrt(delta);
if (sq * sq == delta){
long long x1 = -sq - 3;
if (x1 % 6 == 0){
puts("YES");
goto out;
}
long long x2 = sq - 3;
if (x2 % 6 == 0){
puts("YES");
goto out;
}
}
puts("NO");
out:;
}
return 0;
}