Nickster258

Simple primality test

Jul 8th, 2016
119
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