title: How do you implement AKS test in Java to determine whether a number is prime?
body: <p>I wrote some pseudo code to start with. I am having trouble writing an expandPolynomial() method. Also, I don't know how to represent the arbitrary int x in isPrime().
  Here is a link that explains AKS: <a href="https://www.youtube.com/watch?v=HvMSRWTE2mI" rel="nofollow noreferrer">https://www.youtube.com/watch?v=HvMSRWTE2mI</a></p>
  
  <pre><code>public class Solution {
      public static void main(String[] args) 
      {
          Scanner scan = new Scanner(System.in);
          int n = scan.nextInt();
          System.out.println(isPrime(n));
      }
      private static boolean isPrime(int p)
      {
          /*
          AKS primality test says that if
          ((x-1)^p - (x^p-1)) mod p == 0,
          then p is a prime
          */
          int x;
          boolean prime=true;
          int[] arr = expandPolynomial(x-1, p);
          for (int i=1;i&lt;arr.length-1; i++)
          {
              // arr[0] and arr[arr.length-1] omitted
              // due to the subtraction in the test
              if (arr[i] % p != 0)
              {
                  prime = false; 
              }
          }
          return prime;
      }
      private static int[] expandPolynomial()
      {
          /* 
          return the coefficient of each term
          from the leading term to x^1;
          */
      }
  }
  </code></pre>