>>> exact_prime_factor_count(51242183) 3
(n: int)
| 5 | |
| 6 | |
| 7 | def 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 | |
| 37 | if __name__ == "__main__": |
no outgoing calls
no test coverage detected