hdu 6216 A Cubic number and A Cubic Number
来源:互联网 发布:maven 打包java环境 编辑:程序博客网 时间:2024/05/30 23:00
A Cubic number and A Cubic Number
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 438 Accepted Submission(s): 237
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 numberp (2≤p≤1012) .
For each test case, a line contains a prime number
Output
For each test case, output 'YES' if given p is a difference of two cubic numbers, or 'NO' if not.
Sample Input
102357111317192329
Sample Output
NONONOYESNONONOYESNONO题目大意:题目的意思就是说,给你一个素数P,问是否有两个数的立方差等于p,如果有输出YES,没有输出NO;题目解析:由题目可以得到,由于a^3-b^3=(a-b)(a^2+b^2+ab) 所以(a-b)a-b只有等于1,a^3-b^3的差才会是素数,所以可以得到(i+1)^3-i^3;代码:#include <cstdio>#include <iostream>using namespace std;int main(){ //freopen("in.txt","r",stdin); int T; cin>>T; while(T--) { long long n; cin>>n; for(long long i=1;i<100000000;i++){ if((i+1)*(i+1)*(i+1)-i*i*i>n){ cout<<"NO"<<endl; break; } if((i+1)*(i+1)*(i+1)-i*i*i==n){ cout<<"YES"<<endl; break; } } } return 0;}
阅读全文
0 0
- 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
- 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
- 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
- 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
- A Cubic number and A Cubic Number
- A Cubic number and A Cubic Number
- **A Cubic number and A Cubic Number**
- A Cubic number and A Cubic Number
- A Cubic number and A Cubic Number
- A Cubic number and A Cubic Number
- java-log4j-xml配置 category、logger、boot 标签使用
- 快速查找算法之为ID卡而生
- 连接DB2数据库报错:ERRORCODE=-4220
- Bootstrap介绍
- 从零设计APP(设计)
- hdu 6216 A Cubic number and A Cubic Number
- 算法这一站是新的起点
- 8.数据的可视化-绘制简单的线与点
- AS新建项目卡在Building这里怎么办?
- laydate时间框架的运用
- hdu 2767 Proving Equivalences【scc缩点+搭桥】
- jvm性能相关(jvisualvm远程连接配置)
- 利用BeanMap进行对象与Map的相互转换 (在hibernate中 map集合转对象 用得到<重要>)
- 条款05:了解C++默认编写调用哪些函数