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. Codeforces791 C. Bear and Different Names

    C. Bear and Different Names time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. 三.mysql表的完整性约束

    mysql表的完整性约束 什么是约束 not null    不能为空的 unique      唯一 = 不能重复 primary key 主键 = 不能为空 且 不能重复 foreign key ...

  3. Android中的EventBus

    1.分析 EventBus是一个针对Android的事件发布和订阅的框架,主要功能是替代Intent,Handler,BroadCast在Fragment,Activity,Service,线程之间传 ...

  4. 《大型网站系统与Java中间件实践》

    读了一下,个人认为最好的部分,就是第四章了. CH04 服务框架 4.2 服务设计与实现 // 获取可用服务地址列表 // 确定调用服务目标机器 // 建立连接(Socket) // 请求序列化 // ...

  5. redis知识点杂记

    最近梳理了一下redis的基本知识.本文会从redis的简单使用.redis的数据类型.redis持久化三个方面做简单阐述和总结. 一.Redis基本操作 1.key的规则 不能使用\n空格.其他都可 ...

  6. 去除swagger ui的红色 error 错误提示

    去除swagger ui的红色 error 错误提示 自定义js文件中加入以下的代码. 加入自定义的js方法看这里 http://www.cnblogs.com/wang2650/archive/20 ...

  7. 利用ArcGIS-Server瓦片制作离线地图包(*.tpk)_详细流程

    1.写在前面 本人是综合了好几个资料才最终制作成功,在这个过程中发现网上好多博客写的步骤不是很详细,因此就把自己的详细制作步骤全部分享出来,可以供需要的小伙伴参考. (1)本文档不讨论tpk文件的详细 ...

  8. [UWP]不那么好用的ContentDialog

    ContentDialog是UWP开发中最常用的组件之一,一个体验良好的UWP应用很难避免不去使用它.博客园里也有许多的文章介绍如何来利用ContentDialog实现各种自定义样式的弹窗界面.不过实 ...

  9. Centos7.x gnome 桌面美化

    一.管理工具 gnome是通过gnome-tweak-tool(优化工具)来管理的,可以在左上角的应用程序->工具里找到. 也可以直接在终端输入gnome-tweak-tool来启动它.启动界面 ...

  10. Android:weight,margin,padding详解实例

    weight详解 weight是用来等比例划分区域的属性. 案例代码 <LinearLayout xmlns:android="http://schemas.android.com/a ...