hud6216 A Cubic number and A Cubic Number O(1)时间复杂度
来源:互联网 发布:上海圣剑网络 吴杨观 编辑:程序博客网 时间:2024/05/16 09:30
A Cubic number and A Cubic Number
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 963 Accepted Submission(s): 468
Total Submission(s): 963 Accepted Submission(s): 468
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 = a^3 - b^3;
p = (a-b)(a^2 + ab + b^2)
又因为p为素数,我们可以跟定a-b = 1; 所以p = 3b(b+1) + 1;
如果(p-1)%3!=0,也就不存在b(b+1),直接输出no。
p = (p-1)/3;
b = (int)sqrt(p);
这是p应该等于b(b+1).
AC代码。
#includeusing namespace std;#define ll long longint main(){int tc;ll n;cin>>tc;while(tc--){cin>>n;n-=1;if(n%3){cout<<"NO"<
阅读全文
0 0
- hud6216 A Cubic number and A Cubic Number O(1)时间复杂度
- 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
- 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 HDU
- hdu 6216 A Cubic number and A Cubic Number
- hdu 6216 A Cubic number and A Cubic Number
- 1011 A Cubic number and A Cubic Number
- HD-6216-A Cubic number and A Cubic Number
- HDU6216 A Cubic number and A Cubic Number【思路】
- Tomcat开机自动启动
- VS各种版本工程之间的相互转换
- javascript版括号匹配
- hihoCoder1576 子树中的最小权值 dfs序+线段树
- Xutils完全解析(一):简单介绍
- hud6216 A Cubic number and A Cubic Number O(1)时间复杂度
- 存储账户之间转移虚拟机
- AJAX学习笔记(一)_简介
- Android逆向初级-smali日志注入
- 【干货分享】大数据开发套件DataIDE使用教程
- 锟斤拷?UTF-8与GBK互转,为什么会乱码?
- graham模板整理
- 高斯混合模型--GMM
- eclipse maven 导出项目依赖的jar包