Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Trips
Date: Fri, 19 Mar 2010 19:40:23 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <ho0jv7$k57$1@fred.mathworks.com>
References: <ho0gt2$cv$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1269027623 20647 172.30.248.37 (19 Mar 2010 19:40:23 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 19 Mar 2010 19:40:23 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:618350

"Shaun " <shaunvon@iastate.edu> wrote in message <ho0gt2$cv$1@fred.mathworks.com>...
> I am needing help with a problem.  I posted this yesterday, but without my code I had so far.  
> 
> The problem is this: given a positive integer n, find all unique combination's of 3 positive integers whose product is n.  For example, n=24, you have six triplets:
> 1     1     24
> 1     2     12
> 1     3     8
> 1     4     6
> 2     2     6
> 2     3     4
> All of these sets of numbers multiply to 24.  None of them repeat.
> .........

  That code of yours is rather brute force I would say.  Surely your for-loops can be made a little more sophisticated - something like this:

 for i = 1:n^(1/3)
  m = n/i;
  if round(m) == m
   for j = i:m^(1/2)
    k = m/j;
    if round(k) == k
     (Then i,j,k is your next triple)
     . . . . . 

See if you can figure out why the n^(1/3) or i:m^(1/2).  See if you can show that i, j, and k must be in ascending order.  See if you can demonstrate that no valid triple is missing.

Roger Stafford