<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 2009 is not a prime number. A python program to compute factors.</title>
	<atom:link href="http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/</link>
	<description>Dhananjay Nene's opinions on software programming, design, architecture and the internet</description>
	<lastBuildDate>Sun, 28 Feb 2010 03:58:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: David Sterry</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-8831</link>
		<dc:creator>David Sterry</dc:creator>
		<pubDate>Mon, 29 Jun 2009 05:35:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-8831</guid>
		<description>@Jaime Nice job. I&#039;m surprised it took someone so long to mention this algorithm. When I wrote some code in C to do this, I was trying to generate all primes up to a certain number and I stored the primes I found just as you said. IIRC it took about 8 minutes to generate all primes under 10^7 on a P3 866Mhz.</description>
		<content:encoded><![CDATA[<p>@Jaime Nice job. I&#8217;m surprised it took someone so long to mention this algorithm. When I wrote some code in C to do this, I was trying to generate all primes up to a certain number and I stored the primes I found just as you said. IIRC it took about 8 minutes to generate all primes under 10^7 on a P3 866Mhz.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gurjeet</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-7871</link>
		<dc:creator>Gurjeet</dc:creator>
		<pubDate>Sun, 31 May 2009 08:44:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-7871</guid>
		<description>How aboout going with 6K + 1 where K is a Whole Number.. 
This gives all prime numbers with some numbers whose factors are prime numbers, like 25, 35, etc... So this is also not 100% correct, but can b helpful...</description>
		<content:encoded><![CDATA[<p>How aboout going with 6K + 1 where K is a Whole Number..<br />
This gives all prime numbers with some numbers whose factors are prime numbers, like 25, 35, etc&#8230; So this is also not 100% correct, but can b helpful&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hmm</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-7704</link>
		<dc:creator>Hmm</dc:creator>
		<pubDate>Fri, 22 May 2009 19:55:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-7704</guid>
		<description>Why does it output 1?  The canonical way to write the prime factors of 4 is [2,2], not [1,2,2]. 

From Wikipedia, &quot;Ω(n) for n = 1, 2, 3, ... is 0, 1, 1, 2, ...&quot;

Ω(1) = 0 --&gt; []
Ω(2) = 1 --&gt; [2]
Ω(3) = 1 --&gt; [3]
Ω(4) = 2 --&gt; [2,2]
...</description>
		<content:encoded><![CDATA[<p>Why does it output 1?  The canonical way to write the prime factors of 4 is [2,2], not [1,2,2]. </p>
<p>From Wikipedia, &#8220;Ω(n) for n = 1, 2, 3, &#8230; is 0, 1, 1, 2, &#8230;&#8221;</p>
<p>Ω(1) = 0 &#8211;&gt; []<br />
Ω(2) = 1 &#8211;&gt; [2]<br />
Ω(3) = 1 &#8211;&gt; [3]<br />
Ω(4) = 2 &#8211;&gt; [2,2]<br />
&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jaime</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-4382</link>
		<dc:creator>Jaime</dc:creator>
		<pubDate>Thu, 26 Feb 2009 12:16:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-4382</guid>
		<description>I hope you people realize how inefficient the code you&#039;ve written is... After you&#039;ve divided out all the 2&#039;s from the number, you still try to find out if it is divisible by 4,6,8,10,12... If nothing else, you should only do trial division by odd numbers. Or even better, if you can afford the memory cost, generate first a list of all prime numbers below sqrt(n), and then do trial division by those only...</description>
		<content:encoded><![CDATA[<p>I hope you people realize how inefficient the code you&#39;ve written is&#8230; After you&#39;ve divided out all the 2&#39;s from the number, you still try to find out if it is divisible by 4,6,8,10,12&#8230; If nothing else, you should only do trial division by odd numbers. Or even better, if you can afford the memory cost, generate first a list of all prime numbers below sqrt(n), and then do trial division by those only&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: deeptext</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-3843</link>
		<dc:creator>deeptext</dc:creator>
		<pubDate>Sun, 04 Jan 2009 21:08:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-3843</guid>
		<description>Yes, and I needed to know.  What is the smallest prime factor?&lt;br&gt;I guessed around:  7&lt;br&gt;&lt;br&gt;(Also, your &quot;copy to clipboard&quot; links don&#039;t work for me).</description>
		<content:encoded><![CDATA[<p>Yes, and I needed to know.  What is the smallest prime factor?<br />I guessed around:  7</p>
<p>(Also, your &#8220;copy to clipboard&#8221; links don&#39;t work for me).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gerry B</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-3834</link>
		<dc:creator>Gerry B</dc:creator>
		<pubDate>Fri, 02 Jan 2009 22:45:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-3834</guid>
		<description>There are supposed to be tab indentations.  Not sure how to keep the tabs in a post</description>
		<content:encoded><![CDATA[<p>There are supposed to be tab indentations.  Not sure how to keep the tabs in a post</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gerry B</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-3833</link>
		<dc:creator>Gerry B</dc:creator>
		<pubDate>Fri, 02 Jan 2009 22:42:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-3833</guid>
		<description>I just wrote this code (works in python 3.0 with the special &quot;//&quot; for division of integers).  This code is much faster and will find your prime factors.  I take advantage of the fact that 30=2*3*5, so any primes above 30 must be 1,7,11,13,17,23,or 29 modulo 30, otherwise the number would be divisible by 2,3 or 5.  Here is the function:&lt;br&gt;&lt;br&gt;def pfast(x):&lt;br&gt;	remder = x&lt;br&gt;	outcat=&quot;1&quot;&lt;br&gt;	while 1:&lt;br&gt;		if remder%2==0:&lt;br&gt;			outcat=outcat+&quot;*2&quot;&lt;br&gt;			remder=remder//2&lt;br&gt;		else:&lt;br&gt;			break&lt;br&gt;	while 1:&lt;br&gt;		if remder%3==0:&lt;br&gt;			outcat=outcat+&quot;*3&quot;&lt;br&gt;			remder=remder//3&lt;br&gt;		else:&lt;br&gt;			break&lt;br&gt;	while 1:&lt;br&gt;		if remder%5==0:&lt;br&gt;			outcat=outcat+&quot;*5&quot;&lt;br&gt;			remder=remder//5&lt;br&gt;		else:&lt;br&gt;			break&lt;br&gt;	while 1:&lt;br&gt;		if remder%7==0:&lt;br&gt;			outcat=outcat+&quot;*7&quot;&lt;br&gt;			remder=remder//7&lt;br&gt;		else:&lt;br&gt;			break&lt;br&gt;	while 1:&lt;br&gt;		if remder%11==0:&lt;br&gt;			outcat=outcat+&quot;*11&quot;&lt;br&gt;			remder=remder//11&lt;br&gt;		else:&lt;br&gt;			break&lt;br&gt;	while 1:&lt;br&gt;		if remder%13==0:&lt;br&gt;			outcat=outcat+&quot;*13&quot;&lt;br&gt;			remder=remder//13&lt;br&gt;		else:&lt;br&gt;			break&lt;br&gt;	while 1:&lt;br&gt;		if remder%17==0:&lt;br&gt;			outcat=outcat+&quot;*17&quot;&lt;br&gt;			remder=remder//17&lt;br&gt;		else:&lt;br&gt;			break&lt;br&gt;	while 1:&lt;br&gt;		if remder%19==0:&lt;br&gt;			outcat=outcat+&quot;*19&quot;&lt;br&gt;			remder=remder//19&lt;br&gt;		else:&lt;br&gt;			break&lt;br&gt;	while 1:&lt;br&gt;		if remder%23==0:&lt;br&gt;			outcat=outcat+&quot;*23&quot;&lt;br&gt;			remder=remder//23&lt;br&gt;		else:&lt;br&gt;			break&lt;br&gt;	while 1:&lt;br&gt;		if remder%29==0:&lt;br&gt;			outcat=outcat+&quot;*29&quot;&lt;br&gt;			remder=remder//29&lt;br&gt;		else:&lt;br&gt;			break&lt;br&gt;	c=0&lt;br&gt;	while 1:&lt;br&gt;		top = remder**0.5+1&lt;br&gt;		c=c+30&lt;br&gt;		if c&gt;top:&lt;br&gt;			return outcat+&quot;*&quot;+str(remder)&lt;br&gt;		while 1:&lt;br&gt;			if remder%(c+1)==0:&lt;br&gt;				outcat=outcat+&quot;*&quot;+str(c+1)&lt;br&gt;				remder=remder//(c+1)&lt;br&gt;			else:&lt;br&gt;				break&lt;br&gt;		while 1:&lt;br&gt;			if remder%(c+7)==0:&lt;br&gt;				outcat=outcat+&quot;*&quot;+str(c+7)&lt;br&gt;				remder=remder//(c+7)&lt;br&gt;			else:&lt;br&gt;				break&lt;br&gt;		while 1:&lt;br&gt;			if remder%(c+11)==0:&lt;br&gt;				outcat=outcat+&quot;*&quot;+str(c+11)&lt;br&gt;				remder=remder//(c+11)&lt;br&gt;			else:&lt;br&gt;				break&lt;br&gt;		while 1:&lt;br&gt;			if remder%(c+13)==0:&lt;br&gt;				outcat=outcat+&quot;*&quot;+str(c+13)&lt;br&gt;				remder=remder//(c+13)&lt;br&gt;			else:&lt;br&gt;				break&lt;br&gt;		while 1:&lt;br&gt;			if remder%(c+17)==0:&lt;br&gt;				outcat=outcat+&quot;*&quot;+str(c+17)&lt;br&gt;				remder=remder//(c+17)&lt;br&gt;			else:&lt;br&gt;				break&lt;br&gt;		while 1:&lt;br&gt;			if remder%(c+23)==0:&lt;br&gt;				outcat=outcat+&quot;*&quot;+str(c+23)&lt;br&gt;				remder=remder//(c+23)&lt;br&gt;			else:&lt;br&gt;				break&lt;br&gt;		while 1:&lt;br&gt;			if remder%(c+29)==0:&lt;br&gt;				outcat=outcat+&quot;*&quot;+str(c+29)&lt;br&gt;				remder=remder//(c+29)&lt;br&gt;			else:&lt;br&gt;				break</description>
		<content:encoded><![CDATA[<p>I just wrote this code (works in python 3.0 with the special &#8220;//&#8221; for division of integers).  This code is much faster and will find your prime factors.  I take advantage of the fact that 30=2*3*5, so any primes above 30 must be 1,7,11,13,17,23,or 29 modulo 30, otherwise the number would be divisible by 2,3 or 5.  Here is the function:</p>
<p>def pfast(x):<br />	remder = x<br />	outcat=&#8221;1&#8243;<br />	while 1:<br />		if remder%2==0:<br />			outcat=outcat+&#8221;*2&#8243;<br />			remder=remder//2<br />		else:<br />			break<br />	while 1:<br />		if remder%3==0:<br />			outcat=outcat+&#8221;*3&#8243;<br />			remder=remder//3<br />		else:<br />			break<br />	while 1:<br />		if remder%5==0:<br />			outcat=outcat+&#8221;*5&#8243;<br />			remder=remder//5<br />		else:<br />			break<br />	while 1:<br />		if remder%7==0:<br />			outcat=outcat+&#8221;*7&#8243;<br />			remder=remder//7<br />		else:<br />			break<br />	while 1:<br />		if remder%11==0:<br />			outcat=outcat+&#8221;*11&#8243;<br />			remder=remder//11<br />		else:<br />			break<br />	while 1:<br />		if remder%13==0:<br />			outcat=outcat+&#8221;*13&#8243;<br />			remder=remder//13<br />		else:<br />			break<br />	while 1:<br />		if remder%17==0:<br />			outcat=outcat+&#8221;*17&#8243;<br />			remder=remder//17<br />		else:<br />			break<br />	while 1:<br />		if remder%19==0:<br />			outcat=outcat+&#8221;*19&#8243;<br />			remder=remder//19<br />		else:<br />			break<br />	while 1:<br />		if remder%23==0:<br />			outcat=outcat+&#8221;*23&#8243;<br />			remder=remder//23<br />		else:<br />			break<br />	while 1:<br />		if remder%29==0:<br />			outcat=outcat+&#8221;*29&#8243;<br />			remder=remder//29<br />		else:<br />			break<br />	c=0<br />	while 1:<br />		top = remder**0.5+1<br />		c=c+30<br />		if c&gt;top:<br />			return outcat+&#8221;*&#8221;+str(remder)<br />		while 1:<br />			if remder%(c+1)==0:<br />				outcat=outcat+&#8221;*&#8221;+str(c+1)<br />				remder=remder//(c+1)<br />			else:<br />				break<br />		while 1:<br />			if remder%(c+7)==0:<br />				outcat=outcat+&#8221;*&#8221;+str(c+7)<br />				remder=remder//(c+7)<br />			else:<br />				break<br />		while 1:<br />			if remder%(c+11)==0:<br />				outcat=outcat+&#8221;*&#8221;+str(c+11)<br />				remder=remder//(c+11)<br />			else:<br />				break<br />		while 1:<br />			if remder%(c+13)==0:<br />				outcat=outcat+&#8221;*&#8221;+str(c+13)<br />				remder=remder//(c+13)<br />			else:<br />				break<br />		while 1:<br />			if remder%(c+17)==0:<br />				outcat=outcat+&#8221;*&#8221;+str(c+17)<br />				remder=remder//(c+17)<br />			else:<br />				break<br />		while 1:<br />			if remder%(c+23)==0:<br />				outcat=outcat+&#8221;*&#8221;+str(c+23)<br />				remder=remder//(c+23)<br />			else:<br />				break<br />		while 1:<br />			if remder%(c+29)==0:<br />				outcat=outcat+&#8221;*&#8221;+str(c+29)<br />				remder=remder//(c+29)<br />			else:<br />				break</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhananjay Nene</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-3832</link>
		<dc:creator>Dhananjay Nene</dc:creator>
		<pubDate>Fri, 02 Jan 2009 22:40:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-3832</guid>
		<description>Blame it on google .. it got me the other link first :) and of course the fact that I wanted to get it done quickly. :)</description>
		<content:encoded><![CDATA[<p>Blame it on google .. it got me the other link first <img src='http://blog.dhananjaynene.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and of course the fact that I wanted to get it done quickly. <img src='http://blog.dhananjaynene.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wj32</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-3831</link>
		<dc:creator>wj32</dc:creator>
		<pubDate>Fri, 02 Jan 2009 22:28:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-3831</guid>
		<description>You didn&#039;t see my prime factorization code, then? &lt;a href=&quot;http://wj32.wordpress.com/2007/12/08/prime-factorization-sieve-of-eratosthenes/&quot; rel=&quot;nofollow&quot;&gt;http://wj32.wordpress.com/2007/12/08/prime-fact...&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>You didn&#39;t see my prime factorization code, then? <a href="http://wj32.wordpress.com/2007/12/08/prime-factorization-sieve-of-eratosthenes/" rel="nofollow"></a><a href="http://wj32.wordpress.com/2007/12/08/prime-fact.." rel="nofollow">http://wj32.wordpress.com/2007/12/08/prime-fact..</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: audax</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-3830</link>
		<dc:creator>audax</dc:creator>
		<pubDate>Fri, 02 Jan 2009 22:10:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-3830</guid>
		<description>[i for i in factor(int(sys.argv[index]))]&lt;br&gt;should be just list([factor(int(sys.argv[index])))</description>
		<content:encoded><![CDATA[<p>[i for i in factor(int(sys.argv[index]))]<br />should be just list([factor(int(sys.argv[index])))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gerry B</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-3829</link>
		<dc:creator>Gerry B</dc:creator>
		<pubDate>Fri, 02 Jan 2009 22:02:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-3829</guid>
		<description>sorry I just realized I am using Python 3.0, which changed the rule for division compared to old Python.  Now, to get what you did, the division sign is // and not simply /</description>
		<content:encoded><![CDATA[<p>sorry I just realized I am using Python 3.0, which changed the rule for division compared to old Python.  Now, to get what you did, the division sign is // and not simply /</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gerry B</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-3828</link>
		<dc:creator>Gerry B</dc:creator>
		<pubDate>Fri, 02 Jan 2009 21:30:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-3828</guid>
		<description>How do you get Python to do more than 18 decimal places of accuracy in a division?  When I try your algo I get the following factors:&lt;br&gt;&lt;br&gt;[1037468051.0, 863693, 7, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 29]</description>
		<content:encoded><![CDATA[<p>How do you get Python to do more than 18 decimal places of accuracy in a division?  When I try your algo I get the following factors:</p>
<p>[1037468051.0, 863693, 7, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 29]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhananjay Nene</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-3827</link>
		<dc:creator>Dhananjay Nene</dc:creator>
		<pubDate>Fri, 02 Jan 2009 20:07:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-3827</guid>
		<description>I could&#039;ve .. just chose n**0.5 instead of sqrt(n). Thats already in the code.</description>
		<content:encoded><![CDATA[<p>I could&#39;ve .. just chose n**0.5 instead of sqrt(n). Thats already in the code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: varun thacker</title>
		<link>http://blog.dhananjaynene.com/2009/01/2009-is-not-a-prime-number-a-python-program-to-compute-factors/comment-page-1/#comment-3826</link>
		<dc:creator>varun thacker</dc:creator>
		<pubDate>Fri, 02 Jan 2009 19:32:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.dhananjaynene.com/?p=335#comment-3826</guid>
		<description>why dont you keep the limit variable to like sqrt(n).That can be the highest factor other than itelsf&lt;br&gt;&lt;br&gt;regards,&lt;br&gt;Varun</description>
		<content:encoded><![CDATA[<p>why dont you keep the limit variable to like sqrt(n).That can be the highest factor other than itelsf</p>
<p>regards,<br />Varun</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.638 seconds -->
