Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. 'handy prime number tester, param is long and function is boolean
  2. Function testPrimes(param As Long) As Boolean
  3.  
  4. 'two variables used
  5. Dim x As Integer
  6. Dim ceil As Double
  7.  
  8. 'ceil rounds param to keep O(n) brief
  9. ceil = Math.Round(Math.Sqr(param))
  10.  
  11. 'basic prime number logic
  12. If param = 1 Then
  13. testPrimes = True
  14.  
  15. ElseIf param = 2 Then
  16. testPrimes = True
  17.  
  18. ElseIf param Mod 2 = 0 Then
  19. testPrimes = False
  20.  
  21. Else
  22. For x = 3 To ceil
  23. If param Mod x = 0 Then
  24. testPrimes = False
  25. x = x + 2
  26. End If
  27. Next x
  28.  
  29. testPrimes = True
  30.  
  31. End If
  32.  
  33. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement