the art of
Algorithm
Notes on Analysis and Design



Fundamental Theorem of Arithmetic

Fundamental theorem of arithmetic states that:every positive integer greater than one can be expressed as unique product of primes.for ex,90=233*5 Following is an application of above theorem

1
2
3
4
5
6
7
8
9
10
11
12
13
def primefactors(n):
    i=0
    factors=[]
#here primelist is list of all primes of a given no
    p=primelist[i]
    while p<=n:
        if n%p==0:
            factors.append(p)
            n //=p
        else:
            i +=1
            p=primelist[i]
    return factors