POJ 3518
来源:互联网 发布:淘宝进货网怎么样 编辑:程序博客网 时间:2024/06/05 20:29
【题目分析】
素数筛+二分
【代码】
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;int top=0,n=1299709;bool have[1299710];int pri[1300000],x;inline void init(){ memset(have,false,sizeof have); for (int i=2;i<=1299709;++i) { if (!have[i]) pri[++top]=i; for (int j=1;j<=top&&(pri[j]*i)<=1299709;++j) { have[pri[j]*i]=true; if (i%pri[j]==0) break; } }}int main(){ init(); while (scanf("%d",&x)!=EOF&&x) { if (!have[x]) {printf("0\n"); continue;} int l=1,r=top; while (l<r) { int mid=(l+r)/2+1; if (pri[mid]>x) r=mid-1; else l=mid; } printf("%d\n",pri[l+1]-pri[l]); }}
0 0
- POJ 3518
- POJ 3518
- POJ 3518
- POJ 3518
- poj 3518 Prime Gap
- poj 3518 Prime Gap
- POJ-3518-Prime Gap
- poj 3518 Prime Gap
- poj 3518(二分)
- POJ 3518 Prime Gap
- poj 3518 prime jap
- POJ - 3518 Prime Gap
- POJ 【3518】 Prime Gap
- poj 3518 Prime Gap
- POJ 3518 Prime Gap
- POJ 3518 Prime Gap
- POJ 3518 Prime Gap
- POJ
- [数据结构与算法]模式匹配-数量词
- mysql免安装版安装配置过程中遇到的问题和相关的解决
- 经典问题生产者与消费者java并发线程模拟实现
- iOS 富文本(NSMutableAttributedString)详解
- Android API Level与version的对应关系
- POJ 3518
- 关于时间格式几种简单处理
- 进程通信方式
- NEFU OJ23
- Android:ScaleType与Matrix相关
- 一个用Java实现的双向队列,可以分别在头尾插入和删除节点
- iOS 学习笔记 触摸事件
- queue模拟(Uva Throwing cards away I)
- Flume官方文档翻译之(十二)