题意:给定一个素数,判定它是不是两个立方数之差。

题解:对于a^3+b^3=(a-b)(a^2-a*b+b^2),而一个素数的因子只有1和其本身,在加上(a^2-a*b+b^2)一定是大于1的,所以只有(a-b)为1的时候,才可能为解。预处理一下,打个表就好了。

ac代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
ll ans[];
int mycheck(int l,int r,ll key)
{
while(r-l>)
{
int mid=(l+r)/;
if(ans[mid] > key)
{
r=mid-;
}
else if(ans[mid] < key) l=mid+;
else return ;
}
// cout<<l<<' '<<r<<endl;
for(int i=l;i<=r;i++) if(ans[i]==key) return ; return -;
}
int main()
{
int t;
for(ll i=;i<=;i++)
{
ans[i-]=i*i*i-(i-)*(i-)*(i-);
// if(i<=10) cout<<ans[i-1]<<endl;
} //cout<<ans[800000-1]<<endl;
cin>>t;
while(t--)
{
ll n;
scanf("%lld",&n);
int pos=mycheck(,,n);
if(pos==) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}

hdu 6216 A Cubic number and A Cubic Number的更多相关文章

  1. hdu 6216 A Cubic number and A Cubic Number【数学题】

    hdu 6216 A Cubic number and A Cubic Number[数学] 题意:判断一个素数是否是两个立方数之差,就是验差分.. 题解:只有相邻两立方数之差才可能,,因为x^3-y ...

  2. 2017青岛网络赛1011 A Cubic number and A Cubic Number

    A Cubic number and A Cubic Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/3276 ...

  3. [Javascript] Use Number() to convert to Number if possilbe

    Use map() and Number() to convert to number if possilbe or NaN. var str = ["1","1.23& ...

  4. Ugly Number,Ugly Number II,Super Ugly Number

    一.Ugly Number Write a program to check whether a given number is an ugly number. Ugly numbers are po ...

  5. leetcode 263. Ugly Number 、264. Ugly Number II 、313. Super Ugly Number 、204. Count Primes

    263. Ugly Number 注意:1.小于等于0都不属于丑数 2.while循环的判断不是num >= 0, 而是能被2 .3.5整除,即能被整除才去除这些数 class Solution ...

  6. leetcode 136. Single Number 、 137. Single Number II 、 260. Single Number III(剑指offer40 数组中只出现一次的数字)

    136. Single Number 除了一个数字,其他数字都出现了两遍. 用亦或解决,亦或的特点:1.相同的数结果为0,不同的数结果为1 2.与自己亦或为0,与0亦或为原来的数 class Solu ...

  7. java.sql.SQLException: Io 异常: Invalid number format for port number

    java.sql.SQLException: Io 异常: Invalid number format for port number   jdbc数据库链接配置没有写端口号 ​ 要检查jdbc的配置 ...

  8. Io 异常: Invalid number format for port number

    报错信息: Caused by: java.sql.SQLException: Io 异常: Invalid number format for port number    at oracle.jd ...

  9. a number of 和the number of用法

    a number of 和the number of用法 1.   A number of + 複數名詞 + 複數動詞           =some/或a lot of + 複數名詞 + 複數動詞 ...

  10. HDU 6216 A Cubic number and A Cubic Number【数学思维+枚举/二分】

    Problem Description A cubic number is the result of using a whole number in a multiplication three t ...

随机推荐

  1. ML_Review_LDA(Ch5)

    Note sth about LDA(Linear Discriminant Analysis) 这篇来说说LDA的复习,LDA在第二次作业的博客中也提及了,但是那是作业思考,所以决定再开一篇只说LD ...

  2. Go 语言入门(三)并发

    写在前面 在学习 Go 语言之前,我自己是有一定的 Java 和 C++ 基础的,这篇文章主要是基于A tour of Go编写的,主要是希望记录一下自己的学习历程,加深自己的理解 Go 语言入门(三 ...

  3. 雪花算法(DELPHI实现)

    雪花算法(DELPHI实现) 生成ID能够按照时间有序生成. 分布式系统内不会产生重复id(用workerId来做区分). 自增ID:对于数据敏感场景不宜使用,且不适合于分布式场景. GUID:采用无 ...

  4. NLP 文本预处理

    1.不同类别文本量统计,类别不平衡差异 2.文本长度统计 3.文本处理,比如文本语料中简体与繁体共存,这会加大模型的学习难度.因此,他们对数据进行繁体转简体的处理. 同时,过滤掉了对分类没有任何作用的 ...

  5. Java 签名(SHA1WithRSA、SHA256WithRSA、SHA256withECDSA)

    RSA1.RSA256 签名 public static String MakeSign(String Data) { try { byte[] data = Data.getBytes(); byt ...

  6. OpenSL ES: 利用OpenSL ES播放一个存在于SDcard上的PCM文件

    native-lib.cpp #include <jni.h> #include <string> #include <SLES/OpenSLES.h> #incl ...

  7. Carve ifc failed

    Detected IFC version: IFC2X3 Warning: Sweeper::createTriangulated3DFace, carve::triangulate::incorpo ...

  8. 一百四十八:部署python项目之环境依赖

    环境:centos7 + python3.6 准备工作,生成项目requirements.txt文件,用于存放第三方库和版本信息:pip freeze > requirements.txt,并且 ...

  9. navigationBarTitleText

    想修改整个程序的导航栏,在app.json 文件 修改 "window": { "backgroundTextStyle": "light" ...

  10. 【Leetcode_easy】633. Sum of Square Numbers

    problem 633. Sum of Square Numbers 题意: solution1: 可以从c的平方根,注意即使c不是平方数,也会返回一个整型数.然后我们判断如果 i*i 等于c,说明c ...