HDU 6216 A Cubic number and A Cubic Number(思维)
来源:互联网 发布:python hist alpha 编辑:程序博客网 时间:2024/06/09 18:25
题目地址
题意:给你一个素数num,求有没有两个立方数的差是这个素数。
思路:只有两个相邻的立方数的差是素数,所以我们枚举出每一个差,记录在数组里面,然后通过二分查找,看看能不能查到这个数就好了。
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream>#include <set>#include <cmath>#define LL long longusing namespace std;LL cub[1825794];int main() { cin.sync_with_stdio(false); LL t, n; for (LL i = 1; i <= 1825793; i++){ LL p = i + 1; cub[i] = p*p*p - i*i*i; } cub[0] = 0; cin >> t; while (t--){ cin >> n; bool flag = false; LL px = lower_bound(cub, cub + 1825794, n) - cub; if (cub[px] == n)flag = true; if (flag)cout << "YES" << endl; else cout << "NO" << endl; } 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
- 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
- 1003. 我要通过!(20)
- 《第六章:对象与设计》阅读笔记
- Selenium操作中文时UnicodeDecodeError: 'utf8' codec can't decode 错误
- 守形数
- Linux压缩命令
- HDU 6216 A Cubic number and A Cubic Number(思维)
- java的多态
- Hadoop基本原理
- 一分钟了解负载均衡的一切
- pip 加速
- pthread使用
- 程序员一职也是吃青春饭的吗?
- 学习笔记(三)字典
- 在hibernate中用mysql写入中文乱码(及其他引起乱码的原因)