Skip to content

Instantly share code, notes, and snippets.

@komasaru
Last active January 8, 2018 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/567fb5a4638bed6e94fe9cff5668b629 to your computer and use it in GitHub Desktop.
Save komasaru/567fb5a4638bed6e94fe9cff5668b629 to your computer and use it in GitHub Desktop.
Python script to compute prime fractorization.
#! /usr/local/bin/python3.6
"""
Prime fractorization
"""
import sys
import traceback
class PrimeFractorization:
def __init__(self):
self.a = 2
def decomposit_prime(self, n):
try:
while n >= self.a * self.a:
if n % self.a == 0:
print(self.a, "* ", end="")
n //= self.a
else:
self.a += 1
print(n)
except Exception as e:
raise
if __name__ == '__main__':
if len(sys.argv) < 2:
print("USAGE: ./prime_factorization.py N")
sys.exit(0)
try:
obj = PrimeFractorization()
obj.decomposit_prime(int(sys.argv[1]))
except Exception as e:
traceback.print_exc()
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment