HDU 6216 A Cubic number and A Cubic Number

A Cubic number and A Cubic Number

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


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
  
  
10 2 3 5 7 11 13 17 19 23 29
 

Sample Output
  
  
NO NO NO YES NO NO NO YES NO NO
 

Source
 

Recommend
liuyiding



题意:给一个素数n,n是否能通过a^3-b^3得到
a^3-b^3=(a-b)*(a^2+a*b+b^2),要想a^3-b^3=素数,(a-b)=1,所以满足要求的数一定是两个相邻的数的立方差,(i)^3-(i-1)^3=(3i^2-3*i+1),这个式子不能继续化简为两个式子相乘,所以i^3-(i-1)^3必为素数,可以先打表到两个立方差到1e12,i的范围大概为577352,数据范围较小,直接暴力比较即可



#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

#define pi acos(-1.0)
#define eps 1e-10
#define pf printf
#define sf scanf
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define e tree[rt]
#define _s second
#define _f first
#define all(x) (x).begin,(x).end
#define mem(i,a) memset(i,a,sizeof i)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define mi ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define sq(x) (3*(x)*(x)-3*(i)+1)

const int inf=0x3f3f3f3f;
int t;
ll n,q[10000000];

void dabiao()
{
    ll i;
    for(i=2;i<=577352;i++)
    {
        q[i]=sq(i);
    }
}

int main()
{
    dabiao();
    sf("%d",&t);
    while(t--)
    {
        int tag=0;
        sf("%lld",&n);
        for(int i=2;i<=577351;i++)
            if(n==q[i])
            {
                puts("YES");
                tag=1;
                break;
            }
        if(!tag)
            puts("NO");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值