hdu 6216 规律+二分
来源:互联网 发布:软件项目管理发展前景 编辑:程序博客网 时间:2024/06/11 06:09
思路: 一个素数是否是立方的差, 只要判断是否是两个连续立方数的差。
在线规律查找](http://oeis.org/)
主要区分一下二分的几种写法
#include <stdio.h>#include <string.h>#include <iostream>#include <vector>using namespace std;const int MAXN = 100005;typedef long long LL;int main(){ LL n; int t; scanf("%d", &t); while(t--) { scanf("%lld", &n); LL l=0, r=600000; LL mid; while(l<=r) { mid=(l+r)>>1; if(mid*mid*mid-(mid-1)*(mid-1)*(mid-1)>n) r=mid-1; else l=mid+1; /* if(mid*mid*mid-(mid-1)*(mid-1)*(mid-1)<=n) l=mid+1; else r=mid-1; */ } if(r*r*r-(r-1)*(r-1)*(r-1)==n) puts("YES"); else puts("NO"); } return 0;}
#include <stdio.h>#include <string.h>#include <iostream>#include <vector>using namespace std;const int MAXN = 100005;typedef long long LL;int main(){ LL n; int t; scanf("%d", &t); while(t--) { scanf("%lld", &n); LL l=0, r=600000; LL mid; while(l<=r) { mid=(l+r)>>1; if(mid*mid*mid-(mid-1)*(mid-1)*(mid-1)<n) l=mid+1; else r=mid-1; /* if(mid*mid*mid-(mid-1)*(mid-1)*(mid-1)>=n) r=mid-1; else l=mid+1; */ } if(l*l*l-(l-1)*(l-1)*(l-1)==n) puts("YES"); else puts("NO"); } return 0;}
#include <stdio.h>#include <string.h>#include <iostream>#include <vector>using namespace std;const int MAXN = 100005;typedef long long LL;int main(){ LL n; int t; scanf("%d", &t); while(t--) { scanf("%lld", &n); LL l=0, r=600000; LL mid; while(l<r) { mid=(l+r)>>1; if(mid*mid*mid-(mid-1)*(mid-1)*(mid-1)>=n) r=mid; else l=mid+1; /* if(mid*mid*mid-(mid-1)*(mid-1)*(mid-1)<n) l=mid+1; else r=mid; */ } if(r*r*r-(r-1)*(r-1)*(r-1)==n) puts("YES"); else puts("NO"); } return 0;}
阅读全文
0 0
- hdu 6216 规律+二分
- HDU 5439 Aggregated Counting 找规律+二分
- HDU 5587 Array (找规律_二分)
- HDU 1597 find the nth digit(水规律+二分)
- HDU-6154 CaoHaha's staff (找规律+二分)
- 规律:HDU
- zoj3870 找规律、二分
- hdu 5439 Aggregated Counting(长春网络赛——找规律+二分)
- POJ 3484(规律+二分)
- HDU-6216 推公式+二分
- HDU 2582 规律题
- hdu 1597 找规律
- hdu 4342 数学规律
- HDU-1597(找规律)
- hdu 4475 找规律
- hdu 1020 找规律
- hdu 1868 找规律
- hdu 3184 (规律)
- 4Sum--LeetCode
- poj 2236 Wireless Network(并查集)(有点暴力)
- 集合框架Map的一些基本用法
- netstat查看端口状态及分析
- 删除servlet
- hdu 6216 规律+二分
- I2C总线浅谈之(三)---以C语言实例分析IIC
- service层@Transactional事务控制使用以及注意
- Maven下SSM项目整合笔记05:查询并分页展示
- 下载servlet
- sql多表查询效率提升实战
- MAC下添加添加Lib文件,实现自动提示功能
- EA&UML日拱一卒-活动图::14.2 Behavior StateMachines (6)
- SpringBoot的日志管理