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

Function exact_prime_factor_count

maths/hardy_ramanujanalgo.py:7–34  ·  view source on GitHub ↗

>>> exact_prime_factor_count(51242183) 3

(n: int)

Source from the content-addressed store, hash-verified

5
6
7def exact_prime_factor_count(n: int) -> int:
8 """
9 >>> exact_prime_factor_count(51242183)
10 3
11 """
12 count = 0
13 if n % 2 == 0:
14 count += 1
15 while n % 2 == 0:
16 n = int(n / 2)
17 # the n input value must be odd so that
18 # we can skip one element (ie i += 2)
19
20 i = 3
21
22 while i <= int(math.sqrt(n)):
23 if n % i == 0:
24 count += 1
25 while n % i == 0:
26 n = int(n / i)
27 i = i + 2
28
29 # this condition checks the prime
30 # number n is greater than 2
31
32 if n > 2:
33 count += 1
34 return count
35
36
37if __name__ == "__main__":

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected