A Cubic number and A Cubic Number (水题)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhangxiaoduoduo/article/details/82262270

A Cubic number and A Cubic Number 

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

题意:T个案例,每次输入一个素数p,判断p是否是两个立方数的差。

思路:分解a³-b³

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#define maxn 1010
#define INF 0x3f3f3f3f
#define LL long long
#define ULL unsigned long long
#define E 1e-8
#define mod 1000000007
#define P pair<int,int>
using namespace std;

int main()
{
    int T;
    LL p;
    scanf("%d",&T);
    while(T--){
        scanf("%lld",&p);
        if((p-1)%3==0){
            int flag = 0;
            LL t = (p-1)/3;
            for(LL i=1;i<=sqrt(t)+1;++i){
                if(i*(i-1)==t){
                    flag = 1;
                    printf("YES\n");
                    break;
                }
            }
            if(flag==0) printf("NO\n");
        }
        else{
            printf("NO\n");
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/zhangxiaoduoduo/article/details/82262270