Created
October 17, 2022 01:15
-
-
Save galenseilis/f4fda98b3d4b1dce99e6230bc5cac445 to your computer and use it in GitHub Desktop.
Brute force search of prime factors of a number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def prime_factors(n): | |
| '''Brute-force method of searching for primes.''' | |
| i = 2 | |
| factors = [] | |
| while i * i <= n: | |
| if n % i: | |
| i += 1 | |
| else: | |
| n //= i | |
| factors.append(i) | |
| if n > 1: | |
| factors.append(n) | |
| return factors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment