Skip to content

Instantly share code, notes, and snippets.

@9999years
Created June 9, 2017 03:25
Show Gist options
  • Save 9999years/0032fcf9d4782d5471a49ee663d8aa06 to your computer and use it in GitHub Desktop.
Save 9999years/0032fcf9d4782d5471a49ee663d8aa06 to your computer and use it in GitHub Desktop.
import argparse
parser = argparse.ArgumentParser(
description='Print prime factors of number[s]'
)
parser.add_argument('num', type=int, nargs='*')
args = parser.parse_args()
nums = args.num
def factors(n):
curr = n
i = 2
factors = []
while i <= n / 2:
if curr % i == 0:
curr /= i
factors.append(i)
else:
i += 1
return factors or [1, n]
for n in nums:
print(repr(factors(n))[1:-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment