当前位置:网站首页>LeetCode#204. Count prime
LeetCode#204. Count prime
2022-07-06 15:21:00 【Rufeng ZHHH】
Count all less than nonnegative integers n The number of prime numbers .
Example 1:
Input :n = 10
Output :4
explain : Less than 10 There are a total of 4 individual , They are 2, 3, 5, 7 .
Example 2:
Input :n = 0
Output :0
Example 3:
Input :n = 1
Output :0
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/count-primes
We use Eratosthene screening _ Baidu Encyclopedia
class Solution:
def countPrimes(self, n: int) -> int:
if n <3:
return 0
else:
dp=[1]*n # Create array ( First, it defaults to all primes )
dp[0],dp[1]=0,0 #0 and 1 Not prime
for i in range(2,n):
for i in range(i*i,n,i): # To optimize , from i*i Just start , Reduce duplication
dp[i]=0
return sum(dp) # Prime numbers all correspond to 1边栏推荐
- In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
- 软件测试行业的未来趋势及规划
- Report on the double computer experiment of scoring system based on 485 bus
- ucore lab7 同步互斥 实验报告
- [200 opencv routines] 98 Statistical sorting filter
- Do you know the advantages and disadvantages of several open source automated testing frameworks?
- How to change XML attribute - how to change XML attribute
- Mysql database (I)
- Mysql database (II) DML data operation statements and basic DQL statements
- A method and implementation of using VSTO to prohibit excel cell editing
猜你喜欢

ucore lab8 文件系统 实验报告
What to do when programmers don't modify bugs? I teach you

51 lines of code, self-made TX to MySQL software!

What are the commonly used SQL statements in software testing?

Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
遇到程序员不修改bug时怎么办?我教你

The minimum number of operations to convert strings in leetcode simple problem
Knowledge that you need to know when changing to software testing

Nest and merge new videos, and preset new video titles

Intensive learning notes: Sutton book Chapter III exercise explanation (ex17~ex29)
随机推荐
Global and Chinese market of DVD recorders 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of RF shielding room 2022-2028: Research Report on technology, participants, trends, market size and share
Cadence physical library lef file syntax learning [continuous update]
Eigen User Guide (Introduction)
ArrayList集合
Video scrolling subtitle addition, easy to make with this technique
Investment should be calm
Currently, mysql5.6 is used. Which version would you like to upgrade to?
How to change XML attribute - how to change XML attribute
MySQL数据库(五)视 图 、 存 储 过 程 和 触 发 器
[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)
Common Oracle commands
Stc-b learning board buzzer plays music
Future trend and planning of software testing industry
Global and Chinese markets of Iam security services 2022-2028: Research Report on technology, participants, trends, market size and share
Collection集合与Map集合
What to do when programmers don't modify bugs? I teach you
[200 opencv routines] 98 Statistical sorting filter
Heap, stack, queue
Opencv recognition of face in image