Prime Factor
This algorithm finds all prime factors of given number.
Public Shared Function PrimeFactor(number As Integer) As List(Of Integer)
Dim factors As New List(Of Integer)()
While number Mod 2 = 0
factors.Add(2)
number \= 2
End While
For i As Integer = 3 To Math.Sqrt(number) Step 2
While number Mod i = 0
factors.Add(i)
number \= i
End While
Next
If number > 2 Then
factors.Add(number)
End If
Return factors
End Function
Example
Dim factors = PrimeFactor(488)
Output
2
2
2
61