Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'handy prime number tester, param is long and function is boolean
- Function testPrimes(param As Long) As Boolean
- 'two variables used
- Dim x As Integer
- Dim ceil As Double
- 'ceil rounds param to keep O(n) brief
- ceil = Math.Round(Math.Sqr(param))
- 'basic prime number logic
- If param = 1 Then
- testPrimes = True
- ElseIf param = 2 Then
- testPrimes = True
- ElseIf param Mod 2 = 0 Then
- testPrimes = False
- Else
- For x = 3 To ceil
- If param Mod x = 0 Then
- testPrimes = False
- x = x + 2
- End If
- Next x
- testPrimes = True
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement