暑假选拔赛01 ---- Prime
来源:互联网 发布:天启软件 编辑:程序博客网 时间:2024/05/17 09:44
Problem Description
按从小到大顺序输出[1,6000000]内的所有质数,每个数一行。
Input
没有输入。
Output
如上。 (样例只是给出了答案的头几行)
Sample Input
Sample Output
2
3
5
……
解题思路
参考 素数筛法.
参考代码
#include <stdio.h>#include <string.h>const int maxn = 6000000;bool IsPrime[maxn+10];int prime[maxn/2],tot = 0;int main(){ memset(IsPrime,true,sizeof(IsPrime)); for (int i = 2;i <= maxn;i++){ if (IsPrime[i]) prime[tot++] = i; for (int j = 0;j < tot;j++){ if (i*prime[j] > maxn) break; IsPrime[i*prime[j]] = false; if (i%prime[j] == 0) break; } } for (int i = 0;i < tot;i++) printf("%d\n",prime[i]); return 0;}
0 0
- 暑假选拔赛01 ---- Prime
- 暑假选拔赛01 ---- Chufa
- 暑假选拔赛01 ---- code
- 暑假选拔赛01 ---- 数字问题
- 暑假选拔赛02 ---- Ysequence
- 暑假选拔赛02 ---- money
- 暑假选拔赛02 ---- 可行方案
- 暑假选拔赛02 ---- 最大乘积
- 暑假培训选拔赛的一道题
- 暑假选拔赛02 ---- an easy problem
- 2010-zzuli暑假集训选拔赛四场总结
- 2013年暑假队内选拔赛题解1
- 2013年暑假队内选拔赛题解2
- 2013年暑假队内选拔赛题解3
- 2013年暑假队内选拔赛题解4
- 2016ACM暑假集训 - Prime Ring Problem
- 组队选拔赛01 ---- trener
- 组队选拔赛01 ---- kusac
- C语言运算符优先级 详细列表
- U3D 接GooglePlay遇到的问题
- Python学习笔记(一)
- poj 3301 Texas Trip
- web缓存--Ehcache使用
- 暑假选拔赛01 ---- Prime
- 使用AlarmManager启动广播、服务、页面(Android定时器)
- uva 10120(暴力+结论)
- Xcode编译 No such file or directory
- MySQL主从复制原理以及架构
- 如何让VMware上的虚拟机ping通外网(图解教程)
- 在linux(ubuntu)下部署Egret
- Merge k Sorted Lists
- MyEclipse 8.6中的Drools安装配置