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. unbuntu14.04下的串口软件monicom的使用

    上篇文章写到了将esp-idf中的examples里的helloworld烧写进了esp32的flash里面,本文就讲讲这个例子的测试和一个项目工程的建立. 首先为了得到esp32输出的信息,需要一个 ...

  2. C#+ZXing.dll生成手机路径导航二维码

    1.原谅我先写点废话哈 这两天用C#写一个C端的软件,甲方提出一个很无理的需求(在C端的程序中实现路径导航,关键是这个程序最终是运行在物理隔绝的电脑上的……),头疼了好几天,领导突然想到可以把坐标+百 ...

  3. poj2699

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

  4. 分布式任务调度系统xxl-job搭建

    为解决分布式环境下定时任务的可靠性,稳定性,只执行一次的特性,我找到了个大众点评开源的分布式调度任务解决完整系统,下面我将一步步深入解读该系统,从基本的使用到源码的探究 下载 https://gith ...

  5. Qt之实现360安全卫士主界面代码开源

    匆匆一年又过去了,总结去年一年的节奏就是忙爆了:生活忙.工作忙,值得庆幸的是没有瞎忙:今天打开博客园查看我的博客,才发现几乎差不多一年时间没写博客了:博客文章就是记忆,就是曾经努力过的见证,感谢博客园 ...

  6. axios的Get和Post方法封装及Node后端接收数据

    最近有做一个Vue的小项目,其中用到了尤大大推荐使用的axios,但是使用的过程中遇到了各种各样的问题,所以这次也是将一些心得分享出来. 安装的流程我就简单说一下下吧,在一个自己新建的文件夹中命令行中 ...

  7. Spring Boot - Profile配置

    Profile是什么 Profile我也找不出合适的中文来定义,简单来说,Profile就是Spring Boot可以对不同环境或者指令来读取不同的配置文件. Profile使用 假如有开发.测试.生 ...

  8. HttpWebRequst中https的验证处理问题

    最近在公司项目中使用了HttpWebRequst相关API,运行环境为.Net/Mono 2.0,是一款针对Unity平台的工具.开发过程中碰到了大家可能都碰到过的问题,Http还是Https? 为什 ...

  9. 3-2 模板语法(vue中的内容写法)

    插值表达式.v-text.v-html的用法

  10. 【sping揭秘】15、afterreturning

    @afterreturning 我们同理写几个测试类 package cn.cutter.start.bean; import org.apache.commons.logging.Log; impo ...