Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'Ygo'
- import collections
- import time
- i = n = int(input("Enter number to factor: "))
- time_start = int(round(time.time() * 1000))
- current_factor = 2
- factors = []
- while current_factor < n:
- if n % current_factor == 0:
- factors.append(current_factor)
- n = n / current_factor
- else:
- current_factor += 1
- factors.append(current_factor)
- # print(factors)
- factors_grouped = collections.OrderedDict()
- for factor in factors:
- factors_grouped[factor] = factors.count(factor)
- # print(factors_grouped)
- out = ""
- for key, value in factors_grouped.items():
- out += "{0}^{1} ".format(key, value)
- time_to_complete = int(round(time.time() * 1000)) - time_start
- print("The prime factors of {0} are:".format(i))
- print(out)
- print("Operation took {0} milliseconds".format(time_to_complete))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement