Skip to content

Instantly share code, notes, and snippets.

@galenseilis
Created October 17, 2022 01:15
Show Gist options
  • Select an option

  • Save galenseilis/f4fda98b3d4b1dce99e6230bc5cac445 to your computer and use it in GitHub Desktop.

Select an option

Save galenseilis/f4fda98b3d4b1dce99e6230bc5cac445 to your computer and use it in GitHub Desktop.
Brute force search of prime factors of a number.
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