UVA1644 - Prime Gap
来源:互联网 发布:一本书学会做数据分析 编辑:程序博客网 时间:2024/06/03 16:48
筛选法
#include <stdio.h>typedef unsigned long long llu;const llu M=1299710;const llu N=100000+10;int cnt=0;int a[M];int b[N];void sar(){ llu temp; a[0]=a[1]=1; for(llu i =2; i<M;i++){ if(a[i]==0){ b[cnt++]=i; temp=i*i; while(temp<M) { a[temp]=1 ;temp+=i;} } }}int main(){ sar(); int x; while(scanf("%d",&x)&&x){ for(int i =0;i<100000; i++){ if(b[i]==x){ printf("0\n"); break; } else if(b[i]>x){ printf("%d\n",b[i]-b[i-1]); break; } } } return 0;}
0 0
- UVa1644 Prime Gap
- UVA1644 - Prime Gap
- UVa1644 - Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- uva1644
- d613: Prime Gap
- 1500 Prime Gap
- poj 3518 Prime Gap
- 1500. Prime Gap
- sicily--1500. Prime Gap
- poj 3518 Prime Gap
- PKU3518 Prime Gap
- 23种设计模式全解析
- UVA 10626 Buying Coke (记忆化)
- UTF-8汉字编码
- IT网址分类
- hdu 3127 完全背包 二维限制条件 放置顺序相关性
- UVA1644 - Prime Gap
- android四大组件之Activity - (1)从源码中理解并巧用onWindowFocusChanged(boolean hasFocus)
- 序列化serialVersionUID的作用
- 小小图书馆
- 寒假结记&开学第一天
- 最长回文(Manacher算法 时间复杂度O(n))
- 逐行读取readline 和 逐行写入
- View动画
- c#数组倒序存放