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的更多相关文章

  1. Aizu 0525 Osenbei 搜索 A

    Aizu 0525 Osenbei https://vjudge.net/problem/Aizu-0525 题目: IOI製菓では,創業以来の伝統の製法で煎餅(せんべい)を焼いている.この伝統の製法 ...

  2. 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 ...

  3. Xmanager Power Suit 6.0.0009 最新版注册激活

    Xmanager Power Suit 6.0.0009 最新版注册激活 手工操作步骤Xmanger Power Suit 官方 其实有两种 .exe 文件,一个是用于试用的,在注册的时候不能直接输入 ...

  4. Aizu 2249 & cf 449B

    Aizu 2249 & cf 449B 1.Aizu - 2249 选的边肯定是最短路上的. 如果一个点有多个入度,取价值最小的. #include<bits/stdc++.h> ...

  5. 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 ...

  6. Aizu - 2564 Tree Reconstruction 并查集

    Aizu - 2564 Tree Reconstruction 题意:一个有向图,要使得能确定每一条边的权值,要求是每个点的入权和出权相等,问你最少需要确定多少条边 思路:这题好像有一个定理之类的,对 ...

  7. Aizu - 2555 Everlasting Zero 模拟

    Aizu - 2555 Everlasting Zero 题意:学习技能,每个技能有不同的要求,问能否学习全部特殊技能 思路:枚举每两个技能,得到他们的先后学习关系,如果两个都不能先学的话就是No了, ...

  8. 有根树的表达 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 ...

  9. 0009《SQL必知必会》笔记05-表的创建与约束

    1.创建表:用CREATE TABLE 语句,要指明:表名(不能与现有表名重复).列名.每列的数据类型 CREATE TABLE product ( prod_id ), vend_id ), pro ...

随机推荐

  1. (三)Qt语言国际化

    Vs 2010+ Qt5 实现语言国际化 创建一个工程,cpp代码如下: 1.创建工程 #include "languageinternationalized.h" #includ ...

  2. 深度模拟java动态代理实现机制系类之三

    这里的内容就比较复杂了,要实现的是对任意的接口,对任意指定的方法,以及对任意指定的代理类型进行代理,就更真实的模拟出java虚拟机的动态代理机制 罗列一下这里涉及的类.接口之间的关系,方便大家学习.1 ...

  3. RSS 订阅

    <?xml version="1.0"?><%@ Page Language="C#" AutoEventWireup="true& ...

  4. 【PHP】phpcms html去除空白

    // 文件路径:/phpcms/libs/classes/template_cache.class.php 42行 // 第四第五行是新增的 $content = $this->template ...

  5. WINDOWS下更改MYSQL数据路径(datadir)后服务启动1067解决不能改变mysql数据库存储位置

    晚上安装完MYSQL(系统:深度WINXPSP2, MYSQL版本:5.1.32)后,用MYSQL自带的配置工具配置完发现默认的数据存放路径是:C:/Documents and Settings/Al ...

  6. 原始套接字的简单tcp包嗅探

    原始套接字 sock_raw = socket(AF_INET , SOCK_RAW , IPPROTO_TCP); while(1) { data_size = recvfrom(sock_raw ...

  7. Nginx模块开发1_明白自定义模块的编译流程

    自定义模块的编译流程 --add-module参数 configure使用--add-module参数指定添加模块目录. config脚本 由--add-module指定的目录保存为$ngx-addo ...

  8. plateform_driver_register和plateform_device_register区别

    设备与驱动的两种绑定方式:在设备注册时进行绑定及在驱动注册时进行绑定. 以一个USB设备为例,有两种情形: (1)先插上USB设备并挂到总线中,然后在安装USB驱动程序过程中从总线上遍历各个设备,看驱 ...

  9. 【Jetlang】一个高性能的Java线程库

    actor  Jetlang 提供了一个高性能的Java线程库,该库是 JDK 1.5 中的 java.util.concurrent 包的补充,可用于基于并发消息机制的应用. .net的MS CCR ...

  10. div+css登陆界面案例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...