MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / while_solution

Function while_solution

project_euler/problem_187/sol1.py:94–114  ·  view source on GitHub ↗

Returns the number of composite integers below max_number have precisely two, not necessarily distinct, prime factors. >>> while_solution(30) 10

(max_number: int = 10**8)

Source from the content-addressed store, hash-verified

92
93
94def while_solution(max_number: int = 10**8) -> int:
95 """
96 Returns the number of composite integers below max_number have precisely two,
97 not necessarily distinct, prime factors.
98
99 >>> while_solution(30)
100 10
101 """
102
103 prime_numbers = calculate_prime_numbers(max_number // 2)
104
105 semiprimes_count = 0
106 left = 0
107 right = len(prime_numbers) - 1
108 while left <= right:
109 while prime_numbers[left] * prime_numbers[right] >= max_number:
110 right -= 1
111 semiprimes_count += right - left + 1
112 left += 1
113
114 return semiprimes_count
115
116
117def solution(max_number: int = 10**8) -> int:

Callers

nothing calls this directly

Calls 1

calculate_prime_numbersFunction · 0.70

Tested by

no test coverage detected