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. day_1 Python介绍及计算机组成和系统

    python学习路线 基础语法 - 文件操作 - 函数 - 模块 - 面向对象(类) - 网络编程 - 数据库 - 前段 - 项目 学习方法 wwwh: what-why-where-how #wha ...

  2. poj2699

    神题目=神题解+神读入 题意:n个人比赛, 两两比,共n*(n-1), 赢得1分, n<=10(这给了我们枚举的暗示),如果一个人打败了所有比自己分数高的人, 或者他本身就是分数最高的, 那么他 ...

  3. 聚簇索引(clustered index )和非聚簇索引(secondary index)的区别

    这两个名字虽然都叫做索引,但这并不是一种单独的索引类型,而是一种数据存储方式.对于聚簇索引存储来说,行数据和主键B+树存储在一起,辅助键B+树只存储辅助键和主键,主键和非主键B+树几乎是两种类型的树. ...

  4. .NET手记-ASP.NET MVC快速分页的实现

    对于Web应用,展示List是很常见的需求,随之而来的常见的分页组件.jQuery有现成的分页组件,网上也有着大量的第三方分页组件,都能够快速实现分页功能.但是今天我描述的是用基本的C#和html代码 ...

  5. SOA和微服务架构的区别

    微服务架构强调的第一个重点就是业务系统需要彻底的组件化和服务化,原有的单个业务系统会拆分为多个可以独立开发,设计,运行和运维的小应用.这些小应用之间通过服务完成交互和集成.每个小应用从前端web ui ...

  6. cannot download, /home/azhukov/go is a GOROOT, not a GOPATH

    问题详情: go环境安装好后,运行go代码也没有问题 下载govendor包的时候提示: cannot download, /home/azhukov/go is a GOROOT, not a GO ...

  7. hashcode和equals方法的区别和联系

    说到 hashcode就要和Java中的集合,HashSet,HashMap 关系最为密切. 首先附录两张Java的集合结构图: 图二:(上图的简化版) 从Set集合的特点说起 & Set是如 ...

  8. 211. Orchard学习 二 2、ManualResetEvent 与 AutoResetEvent

    一.Orchard里异步请求处理线程队列的控制 Orchard的Orchard.WarmupStarter模块,为HttpApplication.BeginRequest时间附加了一个异步处理事件:B ...

  9. 从零开始学 Web 之 ES6(五)ES6基础语法三

    大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...

  10. Visual Studio 2012 智能提示功能消失解决办法

    安装为Visual Studio 2012且更新到了Update3,但是发现智能提示功能用不了,查了一下,网上各种资料,重装VS,连重装系统的都有.不过有很多朋友都是使用命令行重置VS的方法解决了这个 ...