FNLMath : Utilities : PRIME
PRIME
Decomposes an integer into its prime factors.
Required Arguments
N — Integer to be decomposed. (Input)
NPF — Number of different prime factors of ABS(N). (Output)
If N is equal to 1, 0, or 1, NPF is set to 0.
IPF — Integer vector of length 13. (Output)
IPF(I) contains the prime factors of the absolute value of N, for I = 1, NPF. The remaining 13  NPF locations are not used.
IEXP — Integer vector of length 13. (Output)
IEXP(I) is the exponent of IPF(I), for I = 1, NPF. The remaining 13  NPF locations are not used.
IPW — Integer vector of length 13. (Output)
IPW(I) contains the quantity IPF(I)**IEXP(I), for I = 1, , NPF. The remaining 13  NPF locations are not used.
FORTRAN 90 Interface
Generic: CALL PRIME (N, NPF, IPF, IPW)
Specific: The specific interface name is PRIME.
FORTRAN 77 Interface
Single: CALL PRIME (N, NPF, IPF, IEXP, IPW)
Description
Routine PRIME decomposes an integer into its prime factors. The number to be factored, N, may not have more than 13 distinct factors. The smallest number with more than 13 factors is about 1.3 × 1016. Most computers do not allow integers of this size.
The routine PRIME is based on a routine by Brenner (1973).
Comments
1. The output from PRIME should be interpreted in the following way:
ABS(N) = IPF(1)**IEXP(1) *  * IPF(NPF)**IEXP(NPF).
Example
This example factors the integer 144 = 2432.
 
USE PRIME_INT
USE UMACH_INT
 
IMPLICIT NONE
INTEGER N
PARAMETER (N=144)
!
INTEGER IEXP(13), IPF(13), IPW(13), NOUT, NPF
! Get prime factors of 144
CALL PRIME (N, NPF, IPF, IEXP, IPW)
! Get output unit number
CALL UMACH (2, NOUT)
! Print results
WRITE (NOUT,99999) N, IPF(1), IPF(2), IEXP(1), IEXP(2), IPW(1), &
IPW(2), NPF
!
99999 FORMAT (' The prime factors for', I5, ' are: ', /, 10X, 2I6, // &
' IEXP =', 2I6, /, ' IPW =', 2I6, /, ' NPF =', I6, /)
END
Output
 
The prime factors for 144 are:
2 3
 
IEXP = 4 2
IPW = 16 9
NPF = 2