Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static bool IsPrime(ulong N)
- {
- if ((N & 1) == 0) return N == 2;
- if (N % 3 == 0) return N == 3;
- if (N == 1) return false;
- if (N > 0xfffffff9ffffffc5) throw new OverflowException();
- ulong p = 1, x = 2, max = (ulong)Math.Sqrt(N);
- while ((p += (x ^= 6)) <= max)
- if (N % p == 0)
- return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement