Problem 003

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

Solution:
Function Prob003() As Long
Dim Src As Long = 600851475143
Dim PrimeCol As New Collection
For tmpVal As Long = 2 To Src
If tmpVal > System.Math.Sqrt(Src) Then Exit For
If IsPrime(tmpVal) = True Then
PrimeCol.Add(tmpVal)
End If
Next
For k As Integer = 1 To PrimeCol.Count
If Src Mod PrimeCol(k) = 0 Then
If PrimeCol(k) > Prob003 Then Prob003 = PrimeCol(k)
End If
Next
End Function

Summary:
This one was kind of a pain. I had forgotten a lot about what makes a prime and the various rules, tricks, etc. when dealing with them…

Share Your Thought