title: Evaluated Powers of Bases if gcd of 3 bases is 1 without using tons of for loops
body: <p>I'm trying to make a program that will evaluate the gcd of 3 numbers (the bases), and if the GCD of <code>base1</code> and <code>base2</code>, <code>base2</code> and <code>base3</code>, and <code>base3</code> and <code>base1</code> are all equal to one, then evaulate the bases to exponents in a range. Basically, what I need to do is figure out if their GCD's are equal to one, then calculate the numbers to powers. Here's what it would look like:</p>
  
  <pre><code>bases = 150
  powers = 150
  base1 = all numbers 1-bases
  base2 = all numbers 1-bases
  base3 = all numbers 1-bases
  if the GCD of all combinations = 1
      do base1^all numbers 3-powers
      do base2^all numbers 3-powers
      do base2^all numbers 3-powers
      then store all of those in an array
  </code></pre>
  
  <p>Now, I've tried using the dreaded <code>for</code> loops, but it is very slow and I'm not considering it a solution. It only works quickly if bases and powers are 10 or below. How can I do this without using <code>for</code> loops? Or, if I have to use a <code>for</code> loop, how can I reduce the number that is used? Could I computate what numbers together's 3 GCD combinations equal 1? The <code>for</code> loop that I've tried is below:</p>
  
  <pre><code>for i = 1:numbers
      for j = 1:numbers
          for k = 1:numbers
              if gcd(i,j) == 1 &amp;&amp; gcd(i,k) == 1 &amp;&amp; gcd(k,j) == 1
                  for a = 3:powers
                      for b = 3:powers
                          for c = 3: powers
                              x = i^a
                              y = j^b
                              z = k^c
                          end
                      end
                  end
              end
          end
      end
  end
  </code></pre>