Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FindPrimes
- {
- public static class PrimeTool
- {
- public static bool IsPrime(ulong candidate)
- {
- // Test whether the parameter is a prime number. Source: http://www.dotnetperls.com/prime
- if ((candidate & 1) == 0)
- {
- if (candidate == 2)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- // Note:
- // ... This version was changed to test the square.
- // ... Original version tested against the square root.
- // ... Also we exclude 1 at the end.
- for (ulong i = 3; (i * i) <= candidate; i += 2)
- {
- if ((candidate % i) == 0)
- {
- return false;
- }
- }
- return candidate != 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement