UVa 406 - Prime Cuts
来源:互联网 发布:centos 7.3 lnmp 编辑:程序博客网 时间:2024/04/27 07:09
题目:给你2个数n,C,确定,不超过n的素数的中间的一个范围。 定义[1,n]上有k个素数。
则k为奇数,输出中间的2*k-1个;k为偶数,输出中间的2*k个。
分析:数论。直接打表计算所有的0-1000的素数,然后求中线向两边找端点即可。
说明:在本题中1是素数。
#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;int used[1001];int prim[1001];int main(){memset( used, 0, sizeof(used) );int count = 0;prim[count ++] = 1;for ( int i = 2 ; i <= 1000 ; ++ i )if ( !used[i] ) {prim[count ++] = i;for ( int j = i<<1 ; j <= 1000 ; j += i )used[j] = 1;}prim[count] = 1001; int n,m; while ( ~scanf("%d%d",&n,&m) ) {printf("%d %d:",n,m);int r = 0;while ( prim[r+1] <= n ) r ++;int mid = r/2;int l = mid;r = mid+(r%2);while ( -- m ) {l --; r ++;if ( l < 0 ) l ++;if ( prim[r] > n ) r --;}while ( l <= r )printf(" %d",prim[l ++]);printf("\n\n"); } return 0;}
0 0
- Uva 406 - Prime Cuts
- UVa 406-Prime Cuts
- UVa 406 - Prime Cuts
- Prime Cuts UVA 406
- UVa OJ 406-Prime Cuts
- uva 406 prim cuts
- prime cuts
- Prime Cuts
- Prime Cuts
- zoj1312 Prime Cuts
- fjnu 1848 Prime Cuts
- JOJ1148:Prime Cuts
- HDU 1319 Prime Cuts
- poj 1595 Prime Cuts
- HDU1319 & PKU3518 - Prime Cuts
- HOJ 1107 Prime Cuts
- hdu1319 Prime Cuts
- hdu1913-Prime Cuts
- Android开发之旅:环境搭建及HelloWorld
- LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- 2014年生日
- 位运算,玩拍七不再怕,判断7的倍数再出妙招
- PHP+MYSQL+APACHE简易环境搭建
- UVa 406 - Prime Cuts
- java复习之线程
- hdu2191
- linux 下安装编译配置 QT
- [LeetCode26]Decode Ways
- effective c++ 学习新得之 条款2 prefer const,enum, inline to #defines
- 关于单例存在某些问具体的原因
- 文件上传将文件保存为二进制
- linux 函数执行时间统计