Skip to content

Commit

Permalink
Added AKS primality test
Browse files Browse the repository at this point in the history
  • Loading branch information
maykulkarni committed May 29, 2017
1 parent 2ef8bf5 commit e5a1e3d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Utils/NumberUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,25 @@ public static BigDecimal bigSquareRoot(BigInteger val) {
return bigSquareRoot(new BigDecimal(val));
}

/**
* Checks if number is prime using AKS Primality test
*
* @param n the number
* @return true if its prime, false otherwise
*/
public static boolean isPrimeAKS(long n) {
if (n <= 1) return false;
if (n <= 3) return true;

if (n % 2 == 0 || n % 3 == 0) return false;

for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;

return true;
}

public double euclideanDist(int x1, int x2, int y1, int y2) {
return Math.sqrt(Math.abs(x1 - x2) * Math.abs(x1 - x2)
+ Math.abs(y1 - y2) * Math.abs(y1 - y2));
Expand Down

0 comments on commit e5a1e3d

Please sign in to comment.