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.
Input
The first of input contains an integer T (1≤T≤100)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)p (2≤p≤1012).
Output
For 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
题意描述:
给出一个数检查一下这个数是不是两个数i(这两个数是aaa和bbb的形式)的差
解题思路:
因为差是一个素数所以这两个数即a,b是相邻的;
列出公式计算出a,b的值并且验证;
Accept Code:
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
//x^3-y^3=p因为立方差是素数所以x=y+1
//带入化简后是3y(y+1)+1=p
int main()
{
long long n,p,T;
cin>>T;
while(T--)
{
cin>>p;
if((p-1)%3)
printf("NO\n");
else
{
n=(int)sqrt((p-1)/3);
if(n*(n+1)==(p-1)/3)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}