POJ 题目3518 Prime Gap(水题)
来源:互联网 发布:java gbk中文转utf-8 编辑:程序博客网 时间:2024/05/22 15:12
Description
The sequence of n − 1 consecutive composite numbers (positive integers that are not prime and not equal to 1) lying between two successive prime numbers p and p + n is called a prime gap of length n. For example, ‹24, 25, 26, 27, 28› between 23 and 29 is a prime gap of length 6.
Your mission is to write a program to calculate, for a given positive integer k, the length of the prime gap that contains k. For convenience, the length is considered 0 in case no prime gap contains k.
Input
The input is a sequence of lines each of which contains a single positive integer. Each positive integer is greater than 1 and less than or equal to the 100000th prime number, which is 1299709. The end of the input is indicated by a line containing a single zero.
Output
The output should be composed of lines each of which contains a single non-negative integer. It is the length of the prime gap that contains the corresponding positive integer in the input if it is a composite number, or 0 otherwise. No other characters should occur in the output.
Sample Input
10112724921700
Sample Output
4060114
Source
#include<stdio.h>#include<string.h>int a[1299750];void fun(){int i,j;for(i=2;i<1299750;i++){if(!a[i]){for(j=i+i;j<1299750;j+=i)a[j]=1;}}}int main(){int n;fun();while(scanf("%d",&n)!=EOF,n){int b,c;b=c=n;while(a[b]){b++;}while(a[c]){c--;}printf("%d\n",b-c);}}
- 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
- 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(素数)
- POJ 3518 Prime Gap 可能会
- POJ 3518 Prime Gap 解题报告
- KMP算法实现字符串的模式匹配完整C代码
- 和大神们学习每天一题(leetcode)-Count and Say
- .Net程序员玩转Android开发---(10)帧布局FrameLayout,androidframelayout
- js添加一行删除的问题
- AS3.0视觉特效:像素风格图像切换
- POJ 题目3518 Prime Gap(水题)
- android中listView下拉刷新
- 软件人员的生涯规划
- 解决arcgis长时间打不开的问题
- < meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" />
- Cocos2dx与UIKit的混编
- 手机QQ侧滑菜单_从源码上一步步解析效果的实现
- Mac OS X 10.10 运行 Eclipse 提示需要安装 Java
- STL list 的相关总结