Function Math Arithmetic Class

FactorNumberToVariantMatrix

Factor a number, filling an array with a list of prime factors and their powers.

Signature (Visual Basic / VBA)

Public Function FactorNumberToVariantMatrix( _
      ByRef rFC() As Variant _
    , ByVal vX As Variant _
    ) As Boolean

Code Example

    Assuming
       Dim avarFactors() As Variant
    for example
       FactorNumberToExpr(12345678) = "2*3^2*47*14593"
       FactorNumberToVariantMatrix(avarFactors(), 12345678) = True
    leaves
       LBound(avarFactors, 1) = 0
       UBound(avarFactors, 1) = 2
       LBound(avarFactors, 2) = 0
       UBound(avarFactors, 2) = 4
       avarFactors(1, 1) = 2
       avarFactors(2, 1) = 1
       avarFactors(1, 2) = 3
       avarFactors(2, 2) = 2
       avarFactors(1, 3) = 47
       avarFactors(2, 3) = 1
       avarFactors(1, 4) = 14593
       avarFactors(2, 4) = 1

Parameters

Parameter Description
rFC The two-dimensional dynamic array of variants which will be filled with the prime factors of the number vX. This two-dimensional array represents a table where the first dimension is the column and the second dimension is the row. The prime factors are stored in column #1, rFC(1, X), and the count of that factor is stored in column #2, rFC(2, X), where X represents the sequence of the prime factor within the list of all prime factors.
vX The number whose prime factors are to be calculated and copied into array rFC. Function returns False and reinitializes rFC to (0 to 2, 0 to 0) if vX is Null or cannot be fixed up to a number. Function returns Null if vX is not between 1 and 2,147,483,647 ( MaxLong ) inclusive.