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 ...
随机推荐
- js中字符和数组一些基本算法题
最近在刷 fcc的题,跟升级打怪一样,一关一关的过,还挺吸引我的.今天抽时间把 Basic Algorithm Scritping 这部分题做了,根据一些提示,还是比较简单的.有些题的处理方式 方法 ...
- Spring IOC整理
示例展示 Spring的一大特点是利用配置的xml文件实现依赖注入. 所谓依赖注入是指把一个业务对象注入另一个业务对象,从而达到对象间的松耦合.(注意是业务对象哦!)依赖注入讲的通俗一点,就是让一个对 ...
- 一步一步学习C++
根据<C++ primer>第五版 总结学习心得. 在实践中,不必全面地使用C++语言的各种特性,而应根据工程的实际情况,适当取舍(譬如动态类型信息,虚拟继承.异常等特性的使用,很值得商榷 ...
- Zedboard VmodCAM PIN Constraint
自己画了一块FMC-VHDCI四层板,外接VmodCAM,接口定义如下 #CAMA PIN CONSTRACT NET "CAMA_D_I[7]" LOC = T17 | IOST ...
- Nginx+Tomcat动静分离
需求:nginx处理用户请求的静态页面,tomcat处理用户请求jsp页面,来实现动态分离,nginx处理静态页面效率远高于tomcat,这样一来就能更好的提高并发,处理性能. 准备软件: 下载jdk ...
- nginx+keepalived双主高可用负载均衡
实验环境及软件版本:CentOS版本: 6.6(2.6.32.-504.el6.x86_64)nginx版本: nginx-1.6.3keepalived版本:keepalived-1.2.7 主LB ...
- Translation perface: <<Professional JavaScript for Web Developers, 3rd Edition>>
It is a huge pitty to breaking translating this book. Sincerly speaking, I am striken by this great ...
- .NET Framework 3.5 安装错误:0x800F0906、0x800F081F、0x800F0907
使用Add-WindowsFeature 照成的问题 I get the failure below.. If I pick the Server 2012 R2 image from 8/15/2 ...
- poj 3237 Tree 树链剖分+线段树
Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edg ...
- java 格式化日期(DateFormat)
import java.text.DateFormat; import java.util.Date; /** * 格式化时间类 DateFormat.FULL = 0 * DateFormat.DE ...