Advertisement
xopsuei

AKS primality test

May 26th, 2014
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.27 KB | None | 0 0
  1. private boolean isPrime(int n)
  2.     {
  3.         if (n == 2 || n == 3)
  4.             return true;
  5.         if (n%2 == 0 || n%3 == 0)
  6.             return false;
  7.  
  8.         int i = 5;
  9.         int w = 2;
  10.         while (i * i <= n)
  11.         {
  12.             if (n % i == 0)
  13.                 return false;
  14.  
  15.             i += w;
  16.             w = 6 - w;
  17.         }
  18.  
  19.         return true;
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement