|
10 | 10 | def is_prime(number: int) -> bool: |
11 | 11 | """Return prime check result for a specified number |
12 | 12 |
|
13 | | - The result of this function is True if a number is prime, otherwise |
14 | | - False. |
15 | | -
|
16 | 13 | :param number: number to check |
17 | 14 | :type number: int |
18 | 15 |
|
19 | 16 | :return: prime check result |
20 | 17 | :rtype: bool |
21 | 18 |
|
| 19 | + The result of this function is True if a number is prime, otherwise |
| 20 | + False. |
| 21 | +
|
22 | 22 | """ |
23 | 23 |
|
24 | 24 | if number < 2: |
@@ -48,31 +48,30 @@ def get_primes(limit: int) -> List[int]: |
48 | 48 | def eratosthenes_sieve(limit: int) -> List[int]: |
49 | 49 | """Return a list of prime numbers till specified limit |
50 | 50 |
|
51 | | - In mathematics, the sieve of Eratosthenes is an ancient algorithm for |
52 | | - finding all prime numbers up to any given limit. |
| 51 | + :param limit: a range limit to look for prime numbers |
| 52 | + :type limit: int |
| 53 | +
|
| 54 | + :return: the list of prime numbers within a specified range |
| 55 | + :rtype: list[int] |
| 56 | +
|
| 57 | + In mathematics, the sieve of Eratosthenes is an ancient algorithm |
| 58 | + for finding all prime numbers up to any given limit. |
53 | 59 |
|
54 | 60 | It does so by iteratively marking as composite (i.e., not prime) the |
55 | 61 | multiples of each prime, starting with the first prime number, 2. |
56 | | - The multiples of a given prime are generated as a sequence of numbers |
57 | | - starting from that prime, with constant difference between them that is |
58 | | - equal to that prime. This is the sieve's key distinction from using |
59 | | - trial division to sequentially test each candidate number for |
60 | | - divisibility by each prime. Once all the multiples of each discovered |
61 | | - prime have been marked as composites, the remaining unmarked numbers |
62 | | - are primes. |
| 62 | + The multiples of a given prime are generated as a sequence of |
| 63 | + numbers starting from that prime, with constant difference between |
| 64 | + them that is equal to that prime. This is the sieve's key |
| 65 | + distinction from using trial division to sequentially test each |
| 66 | + candidate number for divisibility by each prime. Once all the |
| 67 | + multiples of each discovered prime have been marked as composites, |
| 68 | + the remaining unmarked numbers are primes. |
63 | 69 |
|
64 | 70 | This makes this algorithm one of the most efficient approach to find |
65 | 71 | primes within a range. |
66 | 72 |
|
67 | 73 | .. seealso:: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes |
68 | 74 |
|
69 | | - :param limit: a range limit to look for prime numbers |
70 | | - :type limit: int |
71 | | -
|
72 | | - :return: the list of prime numbers within a specified range |
73 | | - :rtype: list[int] |
74 | | -
|
75 | | -
|
76 | 75 | """ |
77 | 76 |
|
78 | 77 | sieve: List[bool] = [False, False] + [True] * limit |
|
0 commit comments