Last active
July 25, 2017 22:18
-
-
Save back-seat-driver/6f2dfc3d1744040af62dae8219d7e69b to your computer and use it in GitHub Desktop.
Prime Factorization Algorithm
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
from Primes_Under_1_000_000 import prime_list | |
''' | |
To return the prime factorization of a number | |
''' | |
def is_div(v,n): | |
if v%n==0: | |
return(True) | |
return(False) | |
def div_return(n,d): | |
return(n//d) | |
def prime_factor(n): | |
index = 0 | |
initial = int(n) | |
prime_factors=[] | |
while initial != 1: | |
if is_div(initial,prime_list[index])==True: | |
prime_factors.append(prime_list[index]) | |
initial = div_return(initial,prime_list[index]) | |
else: | |
index+=1 | |
return(prime_factors) | |
''' | |
To return the first number with a specified number of factors | |
''' | |
def race_factors(n): | |
prime_factors = map(lambda element: element-1, sorted(prime_factor(n),reverse=True)) | |
value = 1 | |
for i in range(len(prime_factors)): | |
value*=prime_list[i]**prime_factors[i] | |
return(value) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment