title: Efficient and faster way to find coprimes elements from an array
body: <p>I'm working on a mini-project.
  I'm tasked to find elements in the array that is coprime with all other values.
  I came up with a method that uses a double for-loop. However, I believe the time complexity is not going to be favorable, especially if the array of elements is huge.</p>
  <p>These are what I have:</p>
  <pre><code>ArrayList&lt;Integer&gt; getAllCoPrimes(int[] inputs) {
      ArrayList&lt;Integer&gt; coprimes = new ArrayList&lt;&gt;();
      int[] elementsCount = new int[inputs.length];
      for (int i = 0; i &lt; inputs.length; i++) {
          int x = inputs[i];
          for (int j = 0; j &lt; inputs.length; j++) {
              int y = inputs[j];
              if (i != j) {
                  if (gcd(x, y) == 1) {
                      elementsCount[i]++;
                      if (elementsCount[i] == inputs.length) //x is a coprime with all the elements in the array
                          coprimes.add(x);
                  }
              }
          }
      }
      return coprimes;
  }
  
  static int gcd(int a, int b) {
    // Everything divides 0
    if (a == 0 || b == 0)
      return 0;
  
    // base case
    if (a == b)
      return a;
  
    // a is greater
    if (a &gt; b)
      return gcd(a - b, b);
  
    return gcd(a, b - a);
  }
  </code></pre>
  <p>I would like to ask is there any way I can improve my method to run more efficiently? Thank you in advance :)</p>