AIZU 0009
Prime Number
Time Limit : 1 sec, Memory Limit : 65536 KB
Japanese version is here
Prime Number
Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n.
A prime number is a natural number which has exactly two distinct
natural number divisors: 1 and itself. For example, the first four prime
numbers are: 2, 3, 5, 7.
Input
Input consists of several datasets. Each dataset has an integer n (n ≤ 999999) in a line.
The number of datasets ≤ 30.
Output
For each dataset, prints the number of prime numbers.
Sample Input
10
3
11
Output for the Sample Input
4
2
5 水题,素数筛选。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; #define maxn 999999 + 5
typedef long long ll; int prime[maxn]; void init() {
for(int i = ; i <= maxn - ; i++) {
prime[i] = i % ;
} prime[] = ; for(int i = ; i * i <= maxn; i++) {
if(!prime[i]) continue;
for(int j = i; j * i <= maxn; j++) {
prime[j * i] = ;
}
} for(int i = ; i <= maxn - ; i++) {
prime[i] += prime[i - ];
}
} int main() {
int n;
init();
while( ~scanf("%d",&n)) {
printf("%d\n",prime[n]);
} return ; }
AIZU 0009的更多相关文章
- Aizu 0525 Osenbei 搜索 A
Aizu 0525 Osenbei https://vjudge.net/problem/Aizu-0525 题目: IOI製菓では,創業以来の伝統の製法で煎餅(せんべい)を焼いている.この伝統の製法 ...
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...
- Xmanager Power Suit 6.0.0009 最新版注册激活
Xmanager Power Suit 6.0.0009 最新版注册激活 手工操作步骤Xmanger Power Suit 官方 其实有两种 .exe 文件,一个是用于试用的,在注册的时候不能直接输入 ...
- Aizu 2249 & cf 449B
Aizu 2249 & cf 449B 1.Aizu - 2249 选的边肯定是最短路上的. 如果一个点有多个入度,取价值最小的. #include<bits/stdc++.h> ...
- Sliding Window - The Smallest Window II(AIZU) && Leetcode 76
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_B For a given array a1,a2,a3,...,aNa1 ...
- Aizu - 2564 Tree Reconstruction 并查集
Aizu - 2564 Tree Reconstruction 题意:一个有向图,要使得能确定每一条边的权值,要求是每个点的入权和出权相等,问你最少需要确定多少条边 思路:这题好像有一个定理之类的,对 ...
- Aizu - 2555 Everlasting Zero 模拟
Aizu - 2555 Everlasting Zero 题意:学习技能,每个技能有不同的要求,问能否学习全部特殊技能 思路:枚举每两个技能,得到他们的先后学习关系,如果两个都不能先学的话就是No了, ...
- 有根树的表达 Aizu - ALDS1_7_A: Rooted Trees
有根树的表达 题目:Rooted Trees Aizu - ALDS1_7_A A graph G = (V, E) is a data structure where V is a finite ...
- 0009《SQL必知必会》笔记05-表的创建与约束
1.创建表:用CREATE TABLE 语句,要指明:表名(不能与现有表名重复).列名.每列的数据类型 CREATE TABLE product ( prod_id ), vend_id ), pro ...
随机推荐
- c语言结构体指针初始化
今天来讨论一下C中的内存管理. 记得上周在饭桌上和同事讨论C语言的崛起时,讲到了内存管理方面 我说所有指针使用前都必须初始化,结构体中的成员指针也是一样 有人反驳说,不是吧,以前做二叉树算法时,他的左 ...
- javascript对象与实例
var person=new Object(); var person2={}; 一切都是对象 person是Object的实例, 也是对象. 第二个person2也是如此,只不过它是采用字面量的方式 ...
- Silverlight浮动窗体 floatablewindow 非模态对话框
1.http://www.cnblogs.com/yinxiangpei/articles/2613913.html 说明:Silverlight的ChildWindow组件给我们的开发带来了便利,比 ...
- 集成环境wamp环境下 memcached的安装
早就听说过memcached,但是一直没实践过.所有今天有时间就搞了一下,哎废了我一上午才搞定!一上午啊,好丢人.特写记录一下 先说一下我遇到的问题:按照别人教程(还有好多)说的,安装后没有任何的错误 ...
- Mysql备份--mysqldump&outfile
1.备份工具mysqldump 客户端和服务器端都能用select outfile 只能写到服务器端 2.按表单位备份 a.单个表备份 mysqldump -uusername -p database ...
- 关于python的环境变量问题
我的ubuntu安装python后,查看所有的环境变量,发现没有PYTHONPATH?对我使用python没太大影响,自己写的模块的路径问题有很多方法解决.但是现在我想将我写的模块放在一个包里,要用到 ...
- SVN四部曲之SVN使用详解进阶
SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版本,这就需要程序员有效的管理代码,在需要的时候可以迅速,准确取出相应的版本. Subversion是什么? ...
- MyEclipse反编译Class文件
对于需要查看Java Class文件源码的筒子们来说,必须在项目中导入Java源码才能查看Class文件的具体实现,这不仅十分的麻烦,因为有时我们并不可以获得Class文件对应的Java源码.今天就给 ...
- C++11右值引用,移动主义
理解1: 左值和右值针对等号而言, 等号左边称为左值, 等号右连称为右值. 理解2: 左值和右值针对表达式而言, 表达式结束后依然存在的持久对象称为左值, 表达式结束后不存在的持久对象称为右值. 理解 ...
- [ios]scrollView实现移动与缩放
实现滑动 1.在viewDidLoad中对scrollview的contentSize属性赋值 告诉他滑动范围. 实现缩放 1.在storyboard的scrollview的attribute标签中设 ...