Last active
January 8, 2018 05:25
-
-
Save komasaru/567fb5a4638bed6e94fe9cff5668b629 to your computer and use it in GitHub Desktop.
Python script to compute prime fractorization.
This file contains 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
#! /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