Primzahlen
01.08.2004 10:15:03
Nepumuk
da heute erwartungsgemäß nicht viel los ist in den Foren, eine kleine Frage.
Kennt jemand einen schnelleren Algorithmus um festzustellen, ob eine Zahl prim ist oder nicht. Zur Zeit verwende ich das:
Private Function IsPrim(ByVal lng_pruefzahl As Long) As Boolean
Dim lng_counter As Long
If lng_pruefzahl Mod 2 = 0 Then Exit Function
If lng_pruefzahl Mod 3 = 0 Then Exit Function
If lng_pruefzahl Mod 5 = 0 Then Exit Function
If lng_pruefzahl Mod 7 = 0 Then Exit Function
For lng_counter = 10 To CLng(lng_pruefzahl ^ 0.5) Step 10
If lng_pruefzahl Mod (lng_counter + 1) = 0 Then Exit Function
If lng_pruefzahl Mod (lng_counter + 3) = 0 Then Exit Function
If lng_pruefzahl Mod (lng_counter + 7) = 0 Then Exit Function
If lng_pruefzahl Mod (lng_counter + 9) = 0 Then Exit Function
Next
IsPrim = True
End Function
Gruß
Nepumuk