<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dreamshire &#187; Prime Factors</title>
	<atom:link href="http://blog.dreamshire.com/tag/prime-factors/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dreamshire.com</link>
	<description>Showing what's behind the curtain</description>
	<lastBuildDate>Wed, 01 Sep 2010 02:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Project Euler Problem 47 Solution</title>
		<link>http://blog.dreamshire.com/2009/06/05/project-euler-problem-47-solution/</link>
		<comments>http://blog.dreamshire.com/2009/06/05/project-euler-problem-47-solution/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 08:51:57 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Project Euler Solutions]]></category>
		<category><![CDATA[Solutions 40-49]]></category>
		<category><![CDATA[Prime Factors]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://blog.dreamshire.com/?p=1465</guid>
		<description><![CDATA[Find the first four consecutive integers to have four distinct primes factors.]]></description>
			<content:encoded><![CDATA[<h4><u>Problem Description</u></h4>
<p>The first two consecutive numbers to have two distinct prime factors are:</p>
<p style="margin-left:100px;">14 = 2 &times; 7<br />15 = 3 &times; 5</p>
<p>The first three consecutive numbers to have three distinct prime factors are:</p>
<p style="margin-left:100px;">644 = 2&sup2; &times; 7 &times; 23<br />645 = 3 &times; 5 &times; 43<br />646 = 2 &times; 17 &times; 19.</p>
<p>Find the first four consecutive integers to have four distinct primes factors. What is the first of these numbers?</p>
<h4><u>Analysis</u></h4>
<p>Simple approach that took only a few minutes to write.  Start with the first number that has 4 distinct prime factors.  Continue to increment from that number until 4 consecutive numbers have four distinct prime factors.</p>
<h4><u>Solution</u></h4>
<p>Runs < 5 seconds in Python.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> Euler <span style="color: #ff7700;font-weight:bold;">import</span> factor
&nbsp;
c = <span style="color: #ff4500;">1</span>
n = <span style="color: #ff4500;">2</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">3</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">5</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">7</span>
<span style="color: #ff7700;font-weight:bold;">while</span> c <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">4</span>:
  n += <span style="color: #ff4500;">1</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>factor<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> == <span style="color: #ff4500;">4</span>: c += <span style="color: #ff4500;">1</span>
  <span style="color: #ff7700;font-weight:bold;">else</span>: c = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Answer to PE47 = &quot;</span>, n-<span style="color: #ff4500;">3</span></pre></div></div>

<h4><u>Comments</u></h4>
<p>More information on the <em>Euler</em> module can be found on the <a href="http://blog.dreamshire.com/2009/03/26/94/">tools page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dreamshire.com/2009/06/05/project-euler-problem-47-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler Problem 23 Solution</title>
		<link>http://blog.dreamshire.com/2009/04/09/project-euler-problem-23-solution/</link>
		<comments>http://blog.dreamshire.com/2009/04/09/project-euler-problem-23-solution/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 03:40:51 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Project Euler Solutions]]></category>
		<category><![CDATA[Solutions 20-29]]></category>
		<category><![CDATA[Complete Problem]]></category>
		<category><![CDATA[Prime Factors]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://blog.dreamshire.com/?p=500</guid>
		<description><![CDATA[Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.]]></description>
			<content:encoded><![CDATA[<h4><u>Problem Description</u></h4>
<p>A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.</p>
<p>A number whose proper divisors are less than the number is called deficient and a number whose proper divisors exceed the number is called abundant.</p>
<p>As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.</p>
<p>Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.</p>
<h4><u>Analysis</u></h4>
<p>According to Wolfram Mathworld&#8217;s discussion on <a href="http://mathworld.wolfram.com/AbundantNumber.html">Abundant Numbers</a>, &#8220;Every number greater than 20161 can be expressed as a sum of two abundant numbers. &#8221;  So our upper bound is 20161 not 28123. </p>
<p>Using our routine from problem 21 to calculate the sum of proper divisors we create a set of abundant numbers on the fly and use Python&#8217;s set operations to make the necessary comparisons.  Any number that can&#8217;t be summed from two abundant numbers in the set are marked as exceptions and totaled.</p>
<h4><u>Solution</u></h4>
<p>Runs < 3 seconds in Python.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> d<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>:
  s = <span style="color: #ff4500;">1</span>
  t = n <span style="color: #66cc66;">**</span> .5
  <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span>+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> n <span style="color: #66cc66;">%</span> i == <span style="color: #ff4500;">0</span>: s += i + n / i
  <span style="color: #ff7700;font-weight:bold;">if</span> t == <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span>: s -= t
  <span style="color: #ff7700;font-weight:bold;">return</span> s
&nbsp;
abn = <span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
s = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">20162</span> <span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">if</span> d<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> n:
    abn.<span style="color: black;">add</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">any</span><span style="color: black;">&#40;</span> <span style="color: black;">&#40;</span>n-a <span style="color: #ff7700;font-weight:bold;">in</span> abn<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> a <span style="color: #ff7700;font-weight:bold;">in</span> abn <span style="color: black;">&#41;</span>:
    s += n
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Answer to PE23 = &quot;</span>, s</pre></div></div>

<h4><u>Comments</u></h4>
<p>OEIS reference to this sequence <a href="http://www.research.att.com/~njas/sequences/A048242">A048242</a>.<br />
This is one of those problems that you shouldn&#8217;t spend too much time on as once you have the answer the problems done; there&#8217;s no more discovery.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dreamshire.com/2009/04/09/project-euler-problem-23-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
