PKU Prime Gap 3518 简单素数
2012-03-13 22:45
267 查看
/* stratege : 素数 URL:http://poj.org/problem?id=3518 Problem: 3518 User: a312745658 Memory: 5684K Time: 94MS Language: C++ Result: Accepted */ #include <iostream> #include <cstdio> #include <cstring> #include <cstdio> using namespace std ; int a[1299710] ; int prime[100001] ; int n ; int main() { int i, j, k, num = 0 ; int tmp ; int cnt = 0 ; int left, right ; for (i = 0; i < 1299710; i ++) a[i] = 0 ; for (i = 2; i < 1299710; i ++) { if (a[i] == 0) { tmp = 2 * i ; while (tmp < 1299710) { a[tmp] = 1 ; tmp += i ; } prime[num++] = i ; } } while (cin >> n && n) { if (a == 0) { cout << 0 << endl ; continue ; } for (i = n-1; i >= 2; i --) if (a[i] == 0) { left = i ; break ; } for (i = n+1; i < 1299710; i ++) if (a[i] == 0) { right = i ; break ; } cout << right - left << endl ; } }
相关文章推荐
- PKU3518 Prime Gap
- 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 - 3518 - Prime Gap(筛素数)
- poj 3518 Prime Gap
- Prime Gap(素数表+二分)
- Prime Gap(素数表+二分法)
- Prime Gap--素数打表
- LA-3883 & POJ-3518 Prime Gap 解题报告
- 习题10-4 UVA 1644 Prime Gap(素数打表+二分查找)
- poj 3518 Prime Gap
- 1500 Prime Gap + 判定素数isPrime的三种方法
- pku1365 Prime Land 小整数素数分解,基础题
- Prime Gap http://poj.org/problem?id=3518
- poj 3518 Prime Gap
- poj 3518 Prime Gap