The prime decomposition of a number is defined as a list of prime numbers
which when all multiplied together, are equal to that number.



Example

 12 = 2 × 2 × 3,  so its prime decomposition is  {2, 2, 3}



Task

Write a function which returns an array or collection which contains the prime decomposition of a given number   



n


{\displaystyle n}

   greater than   1.

If your language does not have an isPrime-like function available,
you may assume that you have a function which determines
whether a number is prime (note its name before your code).

If you would like to test code from this task, you may use code from trial division or the Sieve of Eratosthenes.

Note: The program must not be limited by the word size of your computer or some other artificial limit; it should work for any number regardless of size (ignoring the physical limits of RAM etc).



Related tasks

   count in factors
   factors of an integer
   Sieve of Eratosthenes
   primality by trial division
   factors of a Mersenne number
   trial factoring of a Mersenne number
   partition an integer X into N primes
   sequence of primes by Trial Division


 
PROGRAM DECOMPOSE
 
 
!
! for rosettacode.org
!
 
!VAR NUM,J
 
DIM PF[100]
 
PROCEDURE STORE_FACTOR
   PF[0]=PF[0]+1
   PF[PF[0]]=CA
   I=I/CA
END PROCEDURE
 
PROCEDURE DECOMP(I)
  PF[0]=0  CA=2 ! special case
  LOOP
     IF I=1 THEN EXIT PROCEDURE END IF
     EXIT IF INT(I/CA)*CA<>I
     STORE_FACTOR
  END LOOP
  FOR CA=3 TO INT(SQR(I)) STEP 2 DO
     LOOP
        IF I=1 THEN EXIT PROCEDURE END IF
        EXIT IF INT(I/CA)*CA<>I
        STORE_FACTOR
     END LOOP
  END FOR
  IF I>1 THEN CA=I STORE_FACTOR END IF
END PROCEDURE
 
BEGIN
 ! ----- function generate
 ! in ...  I     ... number
 ! out ... PF[]  ... factors
 !         PF[0] ... # of factors
 ! mod ... CA    ... pr.fact. candidate
 PRINT(CHR$(12);) !CLS
 INPUT("Numero ",NUM)
 DECOMP(NUM)
 PRINT(NUM;"=";)
 FOR J=1 TO PF[0] DO
    PRINT(PF[J];)
 END FOR
 PRINT
END PROGRAM
 