Sicily 1500. Prime Gap
来源:互联网 发布:弱点 知乎 编辑:程序博客网 时间:2024/05/18 02:45
题目大意:求给定数前后质数之间的差。
解题思路:分别记录给定数前一个质数和后一个质数,相减得到差即可。
// 1500.Prime Gap #include <iostream> using namespace std; bool isPrime( int num ){ for( int i = 2; i * i <= num; ++i ){ if( num % i == 0 ) return false; } return true; }int main () { //freopen("D:\\input.txt","r",stdin); int num,before,after; while( cin >> num && num != 0 ){ if( isPrime(num) ){ cout << 0 << endl; }else{ for( int i = num + 1; ; ++i ){ if( isPrime(i) ){ after = i; break; } } for( int i = num - 1; ; --i ){ if( isPrime(i) ){ before = i; break; } } cout << after - before << endl; } } return 0; }
- sicily--1500. Prime Gap
- Sicily 1500. Prime Gap
- sicily 1500.Prime Gap
- Sicily 1500. Prime Gap
- Sicily 1500. Prime Gap
- [sicily]1500. Prime Gap
- sicily 1500. Prime Gap
- Sicily 1500. Prime Gap
- 1500. Prime Gap
- Sicily 1500. Prime Gap | 运用数论结论:10^9以内,两个相邻素数距离不超过400
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- Prime Gap
- d613: Prime Gap
- MTK LCD+KEYPAD背光驱动
- 面向对象的3个基本要素和5个基本设计原则(整理)
- 程序中unicode与多字节字符集的相关问题
- 【CSDN常见问题解答】Java Socket通信(TCP/UDP)
- C语言中结构体在函数中的应用
- Sicily 1500. Prime Gap
- NODEjs完整项目实践
- Delphi7 中类说明
- 网络安全技术简介
- C语言查看内存数据 打开内存窗口
- 基于visual Studio2013解决C语言竞赛题之1036递归求值
- Spring的声明式事务管理<tx:advice/> 有关的设置
- 帐号激活与忘记密码 实例
- 二分(折半)查找-经典算法