A Cubic number and A Cubic Number

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

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

 
a^3-b^3 == p,p为质数,所以a-b=1
 //2017-09-17
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long using namespace std; const int N = ; ll cubic[N+];
ll diff[N+]; bool check(ll p){
int pos = lower_bound(diff+, diff+N, p) - diff;
if(diff[pos] == p)
return true;
return false;
} int main()
{
int T;
scanf("%d", &T);
ll p;
for(ll i = ; i <= N; i++)
cubic[i] = i*i*i;
for(int i = ; i <= N; i++)
diff[i] = cubic[i+]-cubic[i];
while(T--){
scanf("%lld", &p);
if(check(p))
printf("YES\n");
else printf("NO\n");
} return ;
}

HDU6216的更多相关文章

  1. 【HDU6216】 A Cubic number and A Cubic Number 和 广工的加强版

    题目传送门_杭电版 题目传送门_广工版 广工版的是杭电版的加强版. 题意:判断一个质数是否是两个整数的立方差 ---- 数学题 题解: 根据立方差公式:\(a^3 - b^3 = (a - b)(a^ ...

随机推荐

  1. 18.数组(一)之认识java数组

    数组是一个简单的复合数据类型,它是一组有序数据的集合,它当中的每一个数据都具有相同的数据类型,我们通过数组名再加上一个不会越界的下标值来唯一确定数组中的元素. 还有就是,数组是一个特殊的对象. 不管在 ...

  2. Navicat Premium Mac V12.0.22.0 中英文破解 亲测可用

    换了Mac电脑后网上找了好些个 Navicat Premium 破解版本, 特别是CSDN上要积分下载的也不能用,浪费积分下,都是些坑爹破解方法,浪费了好些时间,今天介绍看到的一套有效的破解过程 1. ...

  3. HDFS环境搭建(单节点配置)

    [参考文章]:hadoop集群搭建(hdfs) 1. Hadoop下载 官网下载地址: https://hadoop.apache.org/releases.html,进入官网根据自己需要下载具体的安 ...

  4. 使用autogen生成应用程序遇到问题及解决方法

    从github上下载的代码,运行autogen.sh的时候,上报错误: $ ./autogen.sh --prefix=/usr./autogen.sh: 10: ./autogen.sh: auto ...

  5. Liferay7 BPM门户开发之23: 了解内置工作流(Kaleo Workflow)

    Liferay内置的工作流是企业版的功能,虽然简单粗糙,但依然不支持社区版.既然要用更强大的Activiti来替代它,那就非常有必要学习一下内置工作流的一些思想,以便借鉴. 它的特点: 实体的工作流操 ...

  6. Liferay7 BPM门户开发之17: Portlet 生命周期

    Portlet 生命周期 init() =〉 render() =〉 processAction() =〉 processEvent() =〉 serveResource() =〉destroy() ...

  7. C# signtool error:no certificates were found that met all the given criteria 错误解决方案

    程序运行时报错:signtool error:no certificates were found that met all the given criteria (汉译:符号工具错误:没有找到符合所 ...

  8. 课程四(Convolutional Neural Networks),第二 周(Deep convolutional models: case studies) —— 2.Programming assignments : Keras Tutorial - The Happy House (not graded)

    Keras tutorial - the Happy House Welcome to the first assignment of week 2. In this assignment, you ...

  9. 【Java基本功】一文读懂final关键字的用法

    本文主要介绍了final关键字的基本使用方法及原理 final关键字可以修饰类.方法和引用. 修饰类,该类不能被继承.并且这个类的对象在堆中分配内存后地址不可变. 修饰方法,方法不能被子类重写. 修饰 ...

  10. Spring Boot + Spring Cloud 实现权限管理系统 后端篇(十二):解决跨域问题

    什么是跨域? 同源策略是浏览器的一个安全功能,不同源的客户端脚本在没有明确授权的情况下,不能读写对方资源. 同源策略是浏览器安全的基石. 如果一个请求地址里面的协议.域名和端口号都相同,就属于同源. ...