UVa 1644 - Prime Gap(筛法选素数)
2015-03-19 13:29
411 查看
筛法选素数。
#include <iostream> #include <cstdio> #define MAXN 2333333 using namespace std; int per[MAXN] = {1, 1}; void sul_per() { for(int i = 2; i <= 1300000; i++) if(!per[i]&& i * 2 <= 1300000) for(int j = 2; j * i <= 1300000; j++) per[j * i] = 1; } int main() { int x; sul_per(); while(cin >> x&& x) { if(!per[x]) {cout << "0" << "\n"; continue;} int l = x; int r = x; while(per[++l]); while(per[--r]); cout << l - r << "\n"; } return 0; }
相关文章推荐
- 习题10-4 UVA 1644 Prime Gap(素数打表+二分查找)
- Prime Gap UVA - 1644——筛法建素数表
- UVa 1644 - Prime Gap(筛选求素数)
- UVA - 1644 - Prime Gap(找相邻素数差值)
- Prime Gap UVA - 1644
- Prime Gap UVA - 1644 水题
- UVA1644 - Prime Gap
- UVa1644 Prime Gap
- UVA 1644(p343)----Prime Gap
- UVa 1644 Prime Gap (水题,暴力)
- uva 1644 Prime Gap 二分
- UVA 1415 - Gauss Prime(数论,高斯素数拓展)
- UVA 1415 Gauss Prime(高斯素数)
- UVa 1210 - Sum of Consecutive Prime Numbers(素数+连续和)
- 不同素数间隔(Uva 1644)
- POJ3518_Prime Gap【素数】【水题】
- Sum of Consecutive Prime Numbers UVA - 1210 连续素数之和
- UVA 10539 Almost Prime Numbers( 素数因子)
- UVA1210Sum of Consecutive Prime Numbers(素数打表 + 连续和)
- POJ 3518 Prime Gap 素数