Catalogue
Prime Number
750. Number Of Corner Rectangles
1 | class Solution(object): |
836. Rectangle Overlap
1 | class Solution(object): |
Prime Number
A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers.
is Prime
1 | def isPrime(m): |
204. Count Primes
- Time : O(n)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15class Solution:
def countPrimes(self, n):
if n <= 2:
return 0
primes = [True] * n
primes[0] = primes[1] = False
for i in range(2, int(n**0.5)+1):
if not primes[i]:
continue
k = 2
while i * k < n:
primes[i * k] = False
k += 1
return sum(primes)