Welcome, guest | Sign In | My Account | Store | Cart

Calculates the prime factorization from a number.

Python, 21 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
def primo(n):
    def z(x):
        if x % i : return True
        if x == i: return True
        return False
    nump =[2]+ range(3, n+1, 2) 
    for i in range(3, int((n**0.5)+1),2): 
        nump = filter(z, nump)
    return nump

def mcm(n):
    p=primo(n); mm=[]
    while(n > 1):
        for i in p:
            if (n%i == 0): mm.append(i); n=n/i
    mm.sort()
    return mm                


for k in range(100,121):
    print k," ",mcm(k)
Created by juan on Fri, 19 Sep 2014 (MIT)
Python recipes (4591)
juan's recipes (6)

Required Modules

Other Information and Tasks