title: Java: Finding the least common multiple of two positive integers, within a recursive method, with 2 parameters, and with no other loops or methods
body: <p>I'm trying to write a recursive method for an extra credit homework assignment, that finds the least common multiple of two positive integers. However the method needs to follow these rules...</p>
  
  <ol>
  <li>The method must be static with only two int parameters</li>
  <li>The method must be recursive, and cannot use any loops</li>
  <li>The method can not call any other methods, nor can it call any overloaded methods</li>
  <li>The method returns the least common multiple of the arguments passed to it</li>
  </ol>
  
  <p>My question is, is this even possible without a third parameter?</p>
  
  <p>Let's say the parameters (a, b) have (6, 8) passed as arguments.</p>
  
  <pre><code>public static int findLCM (int a, int b) {
      if (a % b == 0)
          return a;
      else
          return findLCM(a + a, b);
  }
  </code></pre>
  
  <p>What I wanted to do was increase 6 to 12, and make a recursive call with findLCM(12, 8), then 12 would be 18, then finally 24. Since (24 % 8 == 0) then 24 would be the LCM.</p>
  
  <p>However as you can clearly see, this code does not do that, because the statement</p>
  
  <pre><code>return findLCM(a + a, b);
  </code></pre>
  
  <p>would only work with a thrid parameter, then rewritten as</p>
  
  <pre><code>return findLCM(a + originalA, b);
  </code></pre>
  
  <p>I can't seem to find any way it would be possible without adding a 3rd parameter.</p>
  
  <p>I've tried other approaches such as getting the greatest common denominator first, and then using it to find the least common multiple, but it seems this is just not possible without other methods, or at least loops.</p>
  
  <pre><code>// Doesn't work. Attempts to get greatest common denominator first, then apply the formula to find the LCM at the first instance of the method being called
  // but there seems to be no way to really detect when to apply this final formula
  public static int findLCM (int a, int b) {
      int result;
      if (b == 0)
          return a;
      else { 
          result = findLCM(b, a % b);
          // When to return gcd, or return lcm???
          if (result == b)
              return result; 
          else
              return (a * b) / result; // formula for lcm
      }
  }
  </code></pre>
  
  <p>I've thought of trying prime factorization, and then using that to find the lcm, but I'm sure that will have the same problem as getting the gcd and then finding the lcm. It's just not possible without other methods or loops.</p>
  
  <p>I apologize if this question isn't completely coding related, but I would just like to know does any one see something I am missing? Is there actually a way to recursively find the lcm with just two parameters, and no loops or other method calls. Or have I been wracking my brain for nothing? This is a simple java class, I feel like it really shouldn't be this hard. Either the assignment is impossible, or I'm missing something obvious...</p>
  
  <p>Thanks for any help</p>