<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Project Euler 5: Find the Lowest Common Multiple</title>
	<atom:link href="http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/feed/" rel="self" type="application/rss+xml" />
	<link>http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/</link>
	<description>Code, games, chess and everything but the kitchen sink</description>
	<pubDate>Wed, 19 Nov 2008 21:00:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Anonymous</title>
		<link>http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-95196</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 18 Nov 2008 14:34:45 +0000</pubDate>
		<guid isPermaLink="false">http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-95196</guid>
		<description>i finges richtig gagi</description>
		<content:encoded><![CDATA[<p>i finges richtig gagi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-91341</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 24 Oct 2008 01:10:34 +0000</pubDate>
		<guid isPermaLink="false">http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-91341</guid>
		<description>in english please</description>
		<content:encoded><![CDATA[<p>in english please</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dominik</title>
		<link>http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-91337</link>
		<dc:creator>Dominik</dc:creator>
		<pubDate>Thu, 23 Oct 2008 23:04:11 +0000</pubDate>
		<guid isPermaLink="false">http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-91337</guid>
		<description>My solution in java ... needs less than 1 second...

		long factor = 20L;
		int max = 0;
		for (long i = 20L; i  10; j--) {
				if (i % j != 0)
					break;
				else {
					if (factor % j != 0) {
						factor = i;
						max++;
					}
				}

				if (j == 11) {
					System.out.println(i);
					System.exit(0);
				}
			}
		}</description>
		<content:encoded><![CDATA[<p>My solution in java &#8230; needs less than 1 second&#8230;</p>
<p>		long factor = 20L;<br />
		int max = 0;<br />
		for (long i = 20L; i  10; j&#8211;) {<br />
				if (i % j != 0)<br />
					break;<br />
				else {<br />
					if (factor % j != 0) {<br />
						factor = i;<br />
						max++;<br />
					}<br />
				}</p>
<p>				if (j == 11) {<br />
					System.out.println(i);<br />
					System.exit(0);<br />
				}<br />
			}<br />
		}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Vicar</title>
		<link>http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-88336</link>
		<dc:creator>The Vicar</dc:creator>
		<pubDate>Sun, 14 Sep 2008 20:39:43 +0000</pubDate>
		<guid isPermaLink="false">http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-88336</guid>
		<description>Gah! The forum didn't auto-convert my &#60; and &#62; to &#38;lt; and &amg;gt;! Phooey! That code SHOULD look like (assuming that will come through properly if I do it myself -- where's the "preview" function?):

my( @primes, %powers );
for ( $i = 2; $i &#60;= 20; $i++ )
{
	my $prime = 1;
	$j = $i;
	foreach my $x ( @primes )
	{
		my $power = 0;
		while ( ( $j % $x ) == 0 )
		{
			$power++;
			$j /= $x;
			$prime = 0;
		}
		if ( $power &#62; $powers{ $x } )
		{
			$powers{ $x } = $power;
		}
	}
	if ( $prime )
	{
		push( @primes, $i );
		$powers{ $i } = 1;
	}
}
my $out = 1;
foreach my $x ( @primes )
{
	$out *= ( $x ** $powers{ $x } );
}
print $out;</description>
		<content:encoded><![CDATA[<p>Gah! The forum didn&#8217;t auto-convert my &lt; and &gt; to &amp;lt; and &amg;gt;! Phooey! That code SHOULD look like (assuming that will come through properly if I do it myself &#8212; where&#8217;s the &#8220;preview&#8221; function?):</p>
<p>my( @primes, %powers );<br />
for ( $i = 2; $i &lt;= 20; $i++ )<br />
{<br />
	my $prime = 1;<br />
	$j = $i;<br />
	foreach my $x ( @primes )<br />
	{<br />
		my $power = 0;<br />
		while ( ( $j % $x ) == 0 )<br />
		{<br />
			$power++;<br />
			$j /= $x;<br />
			$prime = 0;<br />
		}<br />
		if ( $power &gt; $powers{ $x } )<br />
		{<br />
			$powers{ $x } = $power;<br />
		}<br />
	}<br />
	if ( $prime )<br />
	{<br />
		push( @primes, $i );<br />
		$powers{ $i } = 1;<br />
	}<br />
}<br />
my $out = 1;<br />
foreach my $x ( @primes )<br />
{<br />
	$out *= ( $x ** $powers{ $x } );<br />
}<br />
print $out;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Vicar</title>
		<link>http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-88335</link>
		<dc:creator>The Vicar</dc:creator>
		<pubDate>Sun, 14 Sep 2008 20:34:07 +0000</pubDate>
		<guid isPermaLink="false">http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-88335</guid>
		<description>All the suggestions so far are vastly inefficient in terms of time, though they do lead to the correct answer. It's much faster -- though less memory-efficient -- to build a list of prime factors and find the result by multiplying them out. In Perl:

my( @primes, %factors );
for ( $i = 2; $i  $factors{ $x } )
		{
			$factors{ $x } = $power;
		}
	}
	if ( $prime )
	{
		push( @primes, $i );
		$factors{ $i } = 1;
	}
}
my $out = 1;
foreach my $x ( @primes )
{
	$out *= ( $x ** $factors{ $x } );
}
print $out;
// or, if you prefer, die $out;

This works in a fraction of the time of the second script given in the post. And it works in nearly the same time for much higher upper limits, too: if you try changing the upper limit from 20 to 30, the iterative method takes a long, long time, while looking for prime factors is still practically instantaneous. In fact, the iterative method will stop working entirely when the result is beyond the limit of the integer math of the language, while the factor-finding method will still at least have the right factors, and (in Perl) will still print the result in scientific notation -- the lowest common multiple of the first 200 integers is approximately 3.37293588832926e+89.</description>
		<content:encoded><![CDATA[<p>All the suggestions so far are vastly inefficient in terms of time, though they do lead to the correct answer. It&#8217;s much faster &#8212; though less memory-efficient &#8212; to build a list of prime factors and find the result by multiplying them out. In Perl:</p>
<p>my( @primes, %factors );<br />
for ( $i = 2; $i  $factors{ $x } )<br />
		{<br />
			$factors{ $x } = $power;<br />
		}<br />
	}<br />
	if ( $prime )<br />
	{<br />
		push( @primes, $i );<br />
		$factors{ $i } = 1;<br />
	}<br />
}<br />
my $out = 1;<br />
foreach my $x ( @primes )<br />
{<br />
	$out *= ( $x ** $factors{ $x } );<br />
}<br />
print $out;<br />
// or, if you prefer, die $out;</p>
<p>This works in a fraction of the time of the second script given in the post. And it works in nearly the same time for much higher upper limits, too: if you try changing the upper limit from 20 to 30, the iterative method takes a long, long time, while looking for prime factors is still practically instantaneous. In fact, the iterative method will stop working entirely when the result is beyond the limit of the integer math of the language, while the factor-finding method will still at least have the right factors, and (in Perl) will still print the result in scientific notation &#8212; the lowest common multiple of the first 200 integers is approximately 3.37293588832926e+89.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-83664</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Mon, 04 Aug 2008 12:29:09 +0000</pubDate>
		<guid isPermaLink="false">http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-83664</guid>
		<description>You can also increase efficiency by checking divisibility backwards - start with 19 and work down to 11.  A C based language would look something like this:
for(int i = 19; i &#62; 10; i--)
  if(n%i != 0) 
     break;</description>
		<content:encoded><![CDATA[<p>You can also increase efficiency by checking divisibility backwards - start with 19 and work down to 11.  A C based language would look something like this:<br />
for(int i = 19; i &gt; 10; i&#8211;)<br />
  if(n%i != 0)<br />
     break;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-32433</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 02 Nov 2007 17:02:28 +0000</pubDate>
		<guid isPermaLink="false">http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-32433</guid>
		<description>oh this is confusing :-(</description>
		<content:encoded><![CDATA[<p>oh this is confusing :-(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-25181</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Sat, 15 Sep 2007 08:17:56 +0000</pubDate>
		<guid isPermaLink="false">http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-25181</guid>
		<description>Wow, didn't think of that, James. Thank you :)</description>
		<content:encoded><![CDATA[<p>Wow, didn&#8217;t think of that, James. Thank you :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-23183</link>
		<dc:creator>James</dc:creator>
		<pubDate>Fri, 31 Aug 2007 16:30:05 +0000</pubDate>
		<guid isPermaLink="false">http://timjoh.com/project-euler-5-find-the-lowest-common-multiple/#comment-23183</guid>
		<description>Good job, but your optimisation doesn't have to end there, you can increase the increment as you find extra factors. For example, you start with an increment of 20. When you find the first number that's also a factor of 19 (380), the solution has to be a multiple of it, so you can increase the increment to 380. The first number with 20, 19 and 18 as a factor is 3420, and 20,19,18,17 is 58140! This way you can leap past thousands of numbers that can't be the answer without testing them.</description>
		<content:encoded><![CDATA[<p>Good job, but your optimisation doesn&#8217;t have to end there, you can increase the increment as you find extra factors. For example, you start with an increment of 20. When you find the first number that&#8217;s also a factor of 19 (380), the solution has to be a multiple of it, so you can increase the increment to 380. The first number with 20, 19 and 18 as a factor is 3420, and 20,19,18,17 is 58140! This way you can leap past thousands of numbers that can&#8217;t be the answer without testing them.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
