|
Mit den folgenden zwei Funktionen können Sie eine Zahl in ihre
Primfaktoren zerlegen. Die Funktion PrimesToArray gibt ein Array mit
der Untergrenze 1 zurück, die Funktion
PrimesToCollection eine Visual Basic-Collection.
Public Function PrimesToArray(ByVal Number As Long) _
As Variant
Dim nArray() As Long
Dim nA As Long
Dim nB As Long
Dim nW As Long
Dim i As Integer
Dim nIndex As Long
If Number = 0 Then
Exit Function
End If
ReDim nArray(1 To 10)
nA = Number
nB = 2
nW = nA \ 2
For i = 1 To 10
nW = (nW + (nA \ nW)) \ 2
Next 'i
Do While nA <> 1
Do While nA Mod nB = 0
nA = nA \ nB
nIndex = nIndex + 1
If UBound(nArray) < nIndex Then
ReDim Preserve nArray(1 To nIndex + 10)
End If
nArray(nIndex) = nB
Loop
If nB > nW Then
nB = nA - 2
End If
If nB = 2 Then
nB = 1
End If
nB = nB + 2
Loop
ReDim Preserve nArray(1 To nIndex)
PrimesToArray = nArray
End Function
 |
Die Funktion PrimesToArray zerlegt eine Zahl
in ihre Primfaktoren und gibt diese in einem Array zurück

|
Public Function PrimesToCollection(ByVal Number As Long) _
As Collection
Dim nColl As Collection
Dim nA As Long
Dim nB As Long
Dim nW As Long
Dim i As Integer
If Number = 0 Then
Exit Function
End If
Set nColl = New Collection
nA = Number
nB = 2
nW = nA \ 2
For i = 1 To 10
nW = (nW + (nA \ nW)) \ 2
Next 'i
Do While nA <> 1
Do While nA Mod nB = 0
nA = nA \ nB
nColl.Add nB
Loop
If nB > nW Then
nB = nA - 2
End If
If nB = 2 Then
nB = 1
End If
nB = nB + 2
Loop
Set PrimesToCollection = nColl
End Function
 |
Die Funktion PrimesToCollection zerlegt eine
Zahl in ihre Primfaktoren und diese in einer Collection
zurück

|

|