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

Function slow_solution

project_euler/problem_187/sol1.py:71–91  ·  view source on GitHub ↗

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

(max_number: int = 10**8)

Source from the content-addressed store, hash-verified

69
70
71def slow_solution(max_number: int = 10**8) -> int:
72 """
73 Returns the number of composite integers below max_number have precisely two,
74 not necessarily distinct, prime factors.
75
76 >>> slow_solution(30)
77 10
78 """
79
80 prime_numbers = slow_calculate_prime_numbers(max_number // 2)
81
82 semiprimes_count = 0
83 left = 0
84 right = len(prime_numbers) - 1
85 while left <= right:
86 while prime_numbers[left] * prime_numbers[right] >= max_number:
87 right -= 1
88 semiprimes_count += right - left + 1
89 left += 1
90
91 return semiprimes_count
92
93
94def while_solution(max_number: int = 10**8) -> int:

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected