Sieve of Eratosthenes时间复杂度的感性证明
上代码。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define reg register
const int MAXN=100000;
bool tf[MAXN+10];
int cnt=0;
void work(){
memset(tf,1,sizeof(tf));tf[1]=0;
for(reg int i=2;i<=MAXN;++i){
++cnt;
if(!tf[i]) continue;
for(reg int j=i+i;j<=MAXN;j+=i){
tf[j]=0;
++cnt;
}
}
}
int main(){
work();
printf("%d",cnt);
}
结论:Sieve of Eratosthenes\text{Sieve of Eratosthenes}Sieve of Eratosthenes 的时间复杂度为 O(nloglogn).O(n\log\log n).O(nloglogn).
Sieve of Eratosthenes时间复杂度的感性证明的更多相关文章
- “计数质数”问题的常规思路和Sieve of Eratosthenes算法分析
题目描述 题目来源于 LeetCode 204.计数质数,简单来讲就是求"不超过整数 n 的所有素数个数". 常规思路 一般来讲,我们会先写一个判断 a 是否为素数的 isPrim ...
- [原]素数筛法【Sieve Of Eratosthenes + Sieve Of Euler】
拖了有段时间,今天来总结下两个常用的素数筛法: 1.sieve of Eratosthenes[埃氏筛法] 这是最简单朴素的素数筛法了,根据wikipedia,时间复杂度为 ,空间复杂度为O(n). ...
- 埃拉托色尼筛法(Sieve of Eratosthenes)求素数。
埃拉托色尼筛法(Sieve of Eratosthenes)是一种用来求所有小于N的素数的方法.从建立一个整数2~N的表着手,寻找i? 的整数,编程实现此算法,并讨论运算时间. 由于是通过删除来实现, ...
- algorithm@ Sieve of Eratosthenes (素数筛选算法) & Related Problem (Return two prime numbers )
Sieve of Eratosthenes (素数筛选算法) Given a number n, print all primes smaller than or equal to n. It is ...
- 使用埃拉托色尼筛选法(the Sieve of Eratosthenes)在一定范围内求素数及反素数(Emirp)
Programming 1.3 In this problem, you'll be asked to find all the prime numbers from 1 to 1000. Prime ...
- Burnside引理的感性证明
\(Burnside\)引理的感性证明: 其中:\(G\)是置换集合,\(|G|\)是置换种数,\(T_i\)是第\(i\)类置换中的不动点数. \[L = \frac{1}{|G|} * \sum ...
- 【bzoj4808】【马】二分图最大点独立集+简单感性证明
(上不了p站我要死了,侵权度娘背锅) Description 众所周知,马后炮是中国象棋中很厉害的一招必杀技."马走日字".本来,如果在要去的方向有别的棋子挡住(俗称"蹩 ...
- 【hdu1150】【Machine Schedule】二分图最小点覆盖+简单感性证明
(上不了p站我要死了,侵权度娘背锅) 题目大意 有两台机器A和B以及N个需要运行的任务.每台机器有M种不同的模式,而每个任务都恰好在一台机器上运行.如果它在机器A上运行,则机器A需要设置为模式ai,如 ...
- [Algorithm] Finding Prime numbers - Sieve of Eratosthenes
Given a number N, the output should be the all the prime numbers which is less than N. The solution ...
随机推荐
- Redis是否安装
1.Redis对否安装(安装好了会出现下面对应的代码) [lk@localhost /]$ whereis redis-cli redis-cli: /usr/local/bin/redis-cli ...
- python+selenium自动化测试——浏览器驱动
selenium控制浏览器需要下载对应版本的驱动,并把下载好的驱动解压然后拷贝到python的安装目录. 1.chrome 驱动对应版本及下载地址;https://npm.taobao.org/mir ...
- AirFlow常见问题汇总
airflow常见问题的排查记录如下: 1,airflow怎么批量unpause大量的dag任务 普通少量任务可以通过命令airflow unpause dag_id命令来启动,或者在web界面点 ...
- 《Java并发编程的艺术》读书笔记
一.并发编程的挑战 上下文切换:cpu通过时间片分配算法来循环执行任务,当前任务执行一个时间片后会切换到下一个任务.但是,在切换前会保存上一个任务的状态,以便下次切换回这个任务时,可以再加载这个任务的 ...
- spring中集成shiro进行安全管理
shiro是一款轻量级的安全框架,提供认证.授权.加密和会话管理四个基础功能,除此之外也提供了很好的系统集成方案. 下面将它集成到之前的demo中,在之前spring中使用aop配置事务这篇所附代码的 ...
- docker部署jenkins
步骤一: 查找jenkins镜像(也可以直接去jenkins官网找镜像docker pull jenkins/jenkins)(官方版本文档https://hub.docker.com/_/jenki ...
- event.stopPropagation()、event.preventDefault()与return false的区别
做小demo时经常用到return false来取消默认事件,但一直不是很懂它和preventDefault()等的区别,今天查了查文档和大神们的博客,在这里对相关知识点做一个总结 首先开门见山,总结 ...
- Java源码跟踪阅读技巧
转:https://www.jianshu.com/p/ab865109070c 本文基于Eclipse IDE 1.Quick Type Hierarchy 快速查看类继承体系. 快捷键:Ctrl ...
- shell管道与重定向
输出重定向 $ ls -l > lsoutput 这条命令将ls命令执行后的结果输入出到lsoutput文件中. 在linux shell中使用符号 > ,< 来完成输入输出的重定向 ...
- maven 项目报错org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)解决
idea在使用maven构建的项目中使用mybatis时报错org.apache.ibatis.binding.BindingException: Invalid bound statement (n ...