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 ...
随机推荐
- Fragstats景观分析研究
QQ 交流群: Fragstats景观分析 加群链接:http://url.cn/N4wZ3N
- Linux常用命令--文件的压缩和解压缩
在Linux系统中,我们通常使用的文件压缩命令有:bunzip2 , bzip2 , cpio , gunzip , gzip ,split(切割文件) , zgrep(在压缩文件中寻找匹配的正则表达 ...
- struct和class区别
转载来源:http://blog.sina.com.cn/s/blog_48f587a80100k630.html C++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数据 ...
- C# 汉字转拼音(转)
(一)将汉字转化成全拼代码: private void button1_Click(object sender, EventArgs e) { this.textBox2.Text = Hz2Py.C ...
- MDX : Non Empty v/s NonEmpty
MDX : Non Empty v/s NonEmpty User Rating: / 50 PoorBest Written by Jason Thomas Friday, 07 May 20 ...
- 5种IO模型
Unix下可用的5种I/O模型分别是: 阻塞IO 非阻塞IO IO复用(select和poll) 信号驱动式IO(SIGIO) 异步IO(POSIX的aio系列函数) 阻塞式I/O模型: ...
- 【PHP】phpcms 关联连接修复
function _keylinks($txt, $replacenum = '',$link_mode = 1) { $keywords = $this->data['keywords']; ...
- js中的数组
上网查了一下,js中的数组包含的内容还真不少.先给出两个学习的链接: w3school链接:http://www.w3school.com.cn/js/js_obj_array.asp 博客园链接:h ...
- Python开发【第一篇】Python基础之函数递归
函数递归 递归的本质: 就是一个函数调用另外一个函数. def d(): return '123' def c(): r = d() return r def b(): r = c() return ...
- Linux使用标准IO的调用函数,分3种形式实现
/*根据cp命令的格式要求,设计一个类cp的功能程序,要求使用标准IO的调用函数,分3种形式实现,字符,行,块.并注意函数功能的分层*/ #include<stdio.h> #includ ...