PKU3518 Prime Gap
来源:互联网 发布:劳拉西泮片 知乎 编辑:程序博客网 时间:2024/06/06 19:16
prime gap
仅以素数开头和结束的序列 例如:13 14 15 16 17 (长度为17-13=4)
给定一个整数k ,输出包含 k 的prime gap的长度。 如果k是素数 ,输出0
#include<iostream>#include<math.h>using namespace std;bool Isprime(int n) //素数判断{ int i = 0; for(i = 2; i <=(int)sqrt(n*1.0); i++) if(n % i == 0) return false; return true;} int main(){int i,k,N,s,b;while( scanf("%d",&N)&&N ){if(Isprime(N)){printf("0\n");continue;}i=N+1;while(1){if(Isprime(i)){b=i;break;}i++;}i=N-1;while(1){if(Isprime(i)){s=i;break;}i--;}printf("%d\n",b-s);}return 0;}
- PKU3518 Prime Gap
- HDU1319 & PKU3518 - Prime Cuts
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- d613: Prime Gap
- 1500 Prime Gap
- poj 3518 Prime Gap
- 1500. Prime Gap
- sicily--1500. Prime Gap
- poj 3518 Prime Gap
- POJ-3518-Prime Gap
- Sicily 1500. Prime Gap
- sicily 1500.Prime Gap
- MFC_CDC
- Hibernate读书笔记---继承映射
- 俄罗斯方块88行 代码注释版 (一)
- try catch finally return 的执行顺序
- 自动发QQ消息脚本
- PKU3518 Prime Gap
- 1703 压力释放器
- android中获取手机分辨率
- Shell脚本修改crontab
- LPVOID
- ubuntu下利用dnw软件烧写OK6410开发板
- 1704 叠罗汉
- 107个常用javascript语句
- 俄罗斯方块88行 代码注释版 (二)