hdu 6216 A Cubic number and A Cubic Number
题意:给定一个素数,判定它是不是两个立方数之差。
题解:对于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的更多相关文章
- hdu 6216 A Cubic number and A Cubic Number【数学题】
hdu 6216 A Cubic number and A Cubic Number[数学] 题意:判断一个素数是否是两个立方数之差,就是验差分.. 题解:只有相邻两立方数之差才可能,,因为x^3-y ...
- 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 ...
- [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& ...
- 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 ...
- 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 ...
- leetcode 136. Single Number 、 137. Single Number II 、 260. Single Number III(剑指offer40 数组中只出现一次的数字)
136. Single Number 除了一个数字,其他数字都出现了两遍. 用亦或解决,亦或的特点:1.相同的数结果为0,不同的数结果为1 2.与自己亦或为0,与0亦或为原来的数 class Solu ...
- java.sql.SQLException: Io 异常: Invalid number format for port number
java.sql.SQLException: Io 异常: Invalid number format for port number jdbc数据库链接配置没有写端口号 要检查jdbc的配置 ...
- Io 异常: Invalid number format for port number
报错信息: Caused by: java.sql.SQLException: Io 异常: Invalid number format for port number at oracle.jd ...
- a number of 和the number of用法
a number of 和the number of用法 1. A number of + 複數名詞 + 複數動詞 =some/或a lot of + 複數名詞 + 複數動詞 ...
- 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 ...
随机推荐
- 在 Java 应用程序中加一些 Groovy 进来
如果您一直在阅读这个系列,那么您应该已经看到有各种各样使用 Groovy 的有趣方式,Groovy 的主要优势之一就是它的生产力.Groovy 代码通常要比 Java 代码更容易编写,而且编写起来也更 ...
- VMware与宿主机同一网段
将VMware做为一个物理的虚拟机,设置网段与宿主机在同一子网.
- Windows10下Anaconda虚拟环境下安装pycocotools
0 - 步骤 安装visualcppbuildtools_full.exe(链接:https://blog.csdn.net/u012247418/article/details/82314129) ...
- Elasticsearch .net 记录-1
简介 ElasticSearch是一个开源的分布式搜索引擎,具备高可靠性,支持非常多的企业级搜索用例.像Solr4一样,是基于Lucene构建的.支持时间时间索引和全文检索.官网:http://www ...
- osg #ifdef _WIN32 osg
#ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include <osgViewer/Viewer> #include ...
- django中的多级评论
需求分析 一般论坛中有评论和子评论,这样很容易就成了一个评论树,比如以下情况,先看数据结构: #nid,评论内容,跟帖对象(None为根评论) (1, '111', None), (2, '222', ...
- 浅谈service、DAO层引入(转)
转自 http://www.4u4v.net/mvc-simple-enough-on-the-introduction-of-service-dao-layer.html MVC是web开发中常见的 ...
- [LeetCode] 167. Fraction to Recurring Decimal 分数转循环小数
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- EasyNetQ使用(九)【非泛型的发布&订阅扩展方法,发生错误的情况 】
自从EasyNetQ第一个版本开始,它就可以发布/订阅特定类型的消息. bus.Subscribe<MyMessage>("subscriptionId", x =&g ...
- Egret入门学习日记 --- 第十五篇(书中 6.1~6.9节 内容)
第十五篇(书中 6.1~6.9节 内容) 好的,昨天完成了第五章. 今天来看第六章. 总结重点: 1.如何对组件进行分组? 跟着做: 重点1:如何对组件进行分组? 首先,选中你想要组合的组件. 然后点 ...