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++面试总结(3)
7.vector和list的区别(这个也算是经常问的) vector和数组类似,拥有一段连续的内存空间,并且起始地址不变,这样对随机的读取很有效率(就是我们所有的[]运算符了),因为内存是连续的如果我 ...
- Difference between ref and out parameters
Original link: http://www.dotnet-tricks.com/Tutorial/csharp/K0Hb060414-Difference-between-ref-and-ou ...
- OSX 上初步尝试 asp.net 5
去年微软最令开源狗界振奋的消息就是 ASP.NET 的开放与开源这一消息了. 根据微软的介绍,与我之前的一些总结,可以看到 ASP.NET 以及 .NET 平台会有下面几个变化: 代码使用 Apach ...
- 【Sharing】如何成为一名黑客
[声明]此文为转载,只为收藏. 从小到大听说了无数关于“电脑黑客”的故事,比如XXX入侵美国五角大楼,再比如前几年的“熊猫烧香”病毒,这些故事的主角都被我们的媒体称之为“黑客”.其实这些人,更大程度上 ...
- JQuery 表格 隔行换色 和鼠标滑过的样式
$(document).ready(function () { $(".Pub_TB tbody tr:even td").css("background-color&q ...
- 值类型的Constructor
使用C#的时候我们最熟悉的是类,也就是Reference Type,翻译成中文是引用类型.但是C#还有另外的一种类型往往被我们用的最多缺经常被忽视,这种类型就是值类型(Value Type). 值类型 ...
- webpack使用webpack-dev-middleware进行热重载
新手,刚开始学习webpack,想使用webdevserver,但定制性太差,于是研究了一下使用webpack-dev-middleware进行指定. 根据文档https://www.npmjs.co ...
- 【zendstudio】如何利用zendstudio新建 或导入php项目
一.利用ZendStudio创建 PHP Project 1. 打开ZendStudio, 选择:File à New à PHP Project, 如下图所示: 于是弹出如下界面: 在”Projec ...
- ORACLE AWR 和 ASH
一.关于ASH 我们都知道,用户在 ORACLE 数据库中执行操作时,必然要创建相应的连接和会话, 其中,所有当前的会话信息都保存在动态性能视图 V$SESSION 中,通过该视图,DBA 可 以查看 ...
- (转)Android Support Percent百分比布局
一.概述 周末游戏打得过猛,于是周天熬夜码代码,周一早上浑浑噩噩的发现 android-percent-support-lib-sample(https://github.com/JulienGeno ...