SHARE
TWEET

Simple primality test

Nickster258 Jul 8th, 2016 (edited) 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static boolean prime (long n) {
  2.   if ((n%2)==0) {
  3.     if (n == 2 || n == 3) return true;
  4.     return false;
  5.   } else {
  6.     for (int i = 3; i * i < n; i+=2){
  7.       if ((n % i)==0) {
  8.         return false;
  9.       }
  10.     }
  11.   }
  12.   return true;
  13. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top