<?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>Exploring Binary &#187; Powers of two</title>
	<atom:link href="http://www.exploringbinary.com/category/powers-of-two/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.exploringbinary.com</link>
	<description>Binary Numbers, Binary Code, and Binary Logic</description>
	<lastBuildDate>Tue, 31 Jan 2012 16:38:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>1,073,741,823 Grains of Rice</title>
		<link>http://www.exploringbinary.com/1073741823-grains-of-rice/</link>
		<comments>http://www.exploringbinary.com/1073741823-grains-of-rice/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 22:39:13 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Geometric series]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=330</guid>
		<description><![CDATA[In the children&#8217;s book &#8220;One Grain of Rice: A Mathematical Folktale&#8221; a girl uses her knowledge of exponential growth to trick a greedy king into turning over his stockpile of rice. Hidden in the story are mathematical concepts related to doubling: powers of two, geometric sequences, geometric series, and exponents. I will analyze the story [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/1073741823-grains-of-rice/">1,073,741,823 Grains of Rice</a></p>
]]></description>
			<content:encoded><![CDATA[<p>In the children&#8217;s book &ldquo;One Grain of Rice: A Mathematical Folktale&rdquo; a girl uses her knowledge of exponential growth to trick a greedy king into turning over his stockpile of rice. Hidden in the story are mathematical concepts related to doubling: powers of two, geometric sequences, geometric series, and exponents. I will analyze the story from this perspective, and then discuss my experience reading it to first and third grade students.</p>
<div class="wp-caption aligncenter" style="width: 170px"><img src="http://www.exploringbinary.com/wp-content/uploads/one.grain.of.rice.jpg" alt="One Grain of Rice Book Cover" width="160" height="156"/><p class="wp-caption-text">Front Cover of the Book &ldquo;One Grain of Rice&rdquo;</p></div>
<p><span id="more-330"></span></p>
<h2>Synopsis</h2>
<p>In the story, a girl named Rani is given an amount of rice each day for thirty days: one grain of rice on day one, two grains of rice on day two, four grains of rice on day three, eight grains of rice on day four, etc. In other words, on each day after the first, she receives double the amount of rice she received on the previous day. Since the doubling starts from one grain of rice, the amounts received correspond to the first 30 <a title="Read Rick Regan's Article &ldquo;A Table of Nonnegative Powers of Two&rdquo;" href="http://www.exploringbinary.com/a-table-of-nonnegative-powers-of-two/">nonnegative powers of two</a>.</p>
<p>The story progresses through select days, describing the number of grains received, the capacity and number of containers used to hold them, and the total received to each point. The amounts of each measure of rice are not spelled out for each day, so I filled in the details.</p>
<h2>Containers</h2>
<p>To manage the description of the number of grains of rice, and to put the growth in perspective, the author (Demi) uses these containers: bowls, bags, baskets, and storehouses:</p>
<ul>
<li>1 bowl = 4,096 grains</li>
<li>1 bag = 8 bowls = 32,768 grains</li>
<li>1 basket = 32 bags = 256 bowls = 1,048,576 grains</li>
<li>1 storehouse = 128 baskets = 4,096 bags = 32,768 bowls = 134,217,728 grains</li>
</ul>
<p> (I inferred some of these relationships from the story.)</p>
<p>The units of the containers themselves progress through powers of two &#8212; not only through nonnegative powers of two, but through <a title="Read Rick Regan's Article &ldquo;A Table of Negative Powers of Two&rdquo;" href="http://www.exploringbinary.com/a-table-of-negative-powers-of-two/">negative powers of two</a> as well. Nonnegative powers of two represent whole number units, and negative powers of two represent fractional units. For example, 1,024 grains of rice is 1/4 of a bowl and 2,048 grains is 1/2 a bowl.</p>
<p>A sequence of powers of two is a <strong>geometric sequence</strong>, also known as a geometric progression; in this case, each number in the sequence is double the previous.</p>
<h2>Rice Received, By Day</h2>
<p>I made a table showing the progression of powers of two by day, by measure; negative powers of two amounts are shown in gray (I generated this table, and the ones that follow, with <a href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/" title="Read Rick Regan's Article &ldquo;Exploring Binary Numbers With PARI/GP Calculator&rdquo;">PARI/GP</a> scripts I wrote):</p>
<table class="center" border="1" summary="Rice Received By Day">
<caption><strong>Amount of Rice Received By Day</strong></caption>
<tbody>
<tr>
<th class="center">Day</th>
<th class="center">Grains</th>
<th class="center">Bowls</th>
<th class="center">Bags</th>
<th class="center">Baskets</th>
<th class="center">Storehouses</th>
</tr>
<tr>
<td class="right bolded">1</td>
<td class="right">1</td>
<td class="right grayed">1/4096</td>
<td class="right grayed">1/32768</td>
<td class="right grayed">1/1048576</td>
<td class="right grayed">1/134217728</td>
</tr>
<tr>
<td class="right bolded">2</td>
<td class="right">2</td>
<td class="right grayed">1/2048</td>
<td class="right grayed">1/16384</td>
<td class="right grayed">1/524288</td>
<td class="right grayed">1/67108864</td>
</tr>
<tr>
<td class="right bolded">3</td>
<td class="right">4</td>
<td class="right grayed">1/1024</td>
<td class="right grayed">1/8192</td>
<td class="right grayed">1/262144</td>
<td class="right grayed">1/33554432</td>
</tr>
<tr>
<td class="right">4</td>
<td class="right">8</td>
<td class="right grayed">1/512</td>
<td class="right grayed">1/4096</td>
<td class="right grayed">1/131072</td>
<td class="right grayed">1/16777216</td>
</tr>
<tr>
<td class="right">5</td>
<td class="right">16</td>
<td class="right grayed">1/256</td>
<td class="right grayed">1/2048</td>
<td class="right grayed">1/65536</td>
<td class="right grayed">1/8388608</td>
</tr>
<tr>
<td class="right">6</td>
<td class="right">32</td>
<td class="right grayed">1/128</td>
<td class="right grayed">1/1024</td>
<td class="right grayed">1/32768</td>
<td class="right grayed">1/4194304</td>
</tr>
<tr>
<td class="right">7</td>
<td class="right">64</td>
<td class="right grayed">1/64</td>
<td class="right grayed">1/512</td>
<td class="right grayed">1/16384</td>
<td class="right grayed">1/2097152</td>
</tr>
<tr>
<td class="right">8</td>
<td class="right">128</td>
<td class="right grayed">1/32</td>
<td class="right grayed">1/256</td>
<td class="right grayed">1/8192</td>
<td class="right grayed">1/1048576</td>
</tr>
<tr>
<td class="right bolded">9</td>
<td class="right">256</td>
<td class="right grayed">1/16</td>
<td class="right grayed">1/128</td>
<td class="right grayed">1/4096</td>
<td class="right grayed">1/524288</td>
</tr>
<tr>
<td class="right">10</td>
<td class="right">512</td>
<td class="right grayed">1/8</td>
<td class="right grayed">1/64</td>
<td class="right grayed">1/2048</td>
<td class="right grayed">1/262144</td>
</tr>
<tr>
<td class="right">11</td>
<td class="right">1024</td>
<td class="right grayed">1/4</td>
<td class="right grayed">1/32</td>
<td class="right grayed">1/1024</td>
<td class="right grayed">1/131072</td>
</tr>
<tr>
<td class="right bolded">12</td>
<td class="right">2048</td>
<td class="right grayed">1/2</td>
<td class="right grayed">1/16</td>
<td class="right grayed">1/512</td>
<td class="right grayed">1/65536</td>
</tr>
<tr>
<td class="right bolded">13</td>
<td class="right">4096</td>
<td class="right">1</td>
<td class="right grayed">1/8</td>
<td class="right grayed">1/256</td>
<td class="right grayed">1/32768</td>
</tr>
<tr>
<td class="right">14</td>
<td class="right">8192</td>
<td class="right">2</td>
<td class="right grayed">1/4</td>
<td class="right grayed">1/128</td>
<td class="right grayed">1/16384</td>
</tr>
<tr>
<td class="right">15</td>
<td class="right">16384</td>
<td class="right">4</td>
<td class="right grayed">1/2</td>
<td class="right grayed">1/64</td>
<td class="right grayed">1/8192</td>
</tr>
<tr>
<td class="right bolded">16</td>
<td class="right">32768</td>
<td class="right">8</td>
<td class="right">1</td>
<td class="right grayed">1/32</td>
<td class="right grayed">1/4096</td>
</tr>
<tr>
<td class="right">17</td>
<td class="right">65536</td>
<td class="right">16</td>
<td class="right">2</td>
<td class="right grayed">1/16</td>
<td class="right grayed">1/2048</td>
</tr>
<tr>
<td class="right">18</td>
<td class="right">131072</td>
<td class="right">32</td>
<td class="right">4</td>
<td class="right grayed">1/8</td>
<td class="right grayed">1/1024</td>
</tr>
<tr>
<td class="right">19</td>
<td class="right">262144</td>
<td class="right">64</td>
<td class="right">8</td>
<td class="right grayed">1/4</td>
<td class="right grayed">1/512</td>
</tr>
<tr>
<td class="right bolded">20</td>
<td class="right">524288</td>
<td class="right">128</td>
<td class="right">16</td>
<td class="right grayed">1/2</td>
<td class="right grayed">1/256</td>
</tr>
<tr>
<td class="right bolded">21</td>
<td class="right">1048576</td>
<td class="right">256</td>
<td class="right">32</td>
<td class="right">1</td>
<td class="right grayed">1/128</td>
</tr>
<tr>
<td class="right">22</td>
<td class="right">2097152</td>
<td class="right">512</td>
<td class="right">64</td>
<td class="right">2</td>
<td class="right grayed">1/64</td>
</tr>
<tr>
<td class="right">23</td>
<td class="right">4194304</td>
<td class="right">1024</td>
<td class="right">128</td>
<td class="right">4</td>
<td class="right grayed">1/32</td>
</tr>
<tr>
<td class="right bolded">24</td>
<td class="right">8388608</td>
<td class="right">2048</td>
<td class="right">256</td>
<td class="right">8</td>
<td class="right grayed">1/16</td>
</tr>
<tr>
<td class="right">25</td>
<td class="right">16777216</td>
<td class="right">4096</td>
<td class="right">512</td>
<td class="right">16</td>
<td class="right grayed">1/8</td>
</tr>
<tr>
<td class="right">26</td>
<td class="right">33554432</td>
<td class="right">8192</td>
<td class="right">1024</td>
<td class="right">32</td>
<td class="right grayed">1/4</td>
</tr>
<tr>
<td class="right bolded">27</td>
<td class="right">67108864</td>
<td class="right">16384</td>
<td class="right">2048</td>
<td class="right">64</td>
<td class="right grayed">1/2</td>
</tr>
<tr>
<td class="right">28</td>
<td class="right">134217728</td>
<td class="right">32768</td>
<td class="right">4096</td>
<td class="right">128</td>
<td class="right">1</td>
</tr>
<tr>
<td class="right bolded">29</td>
<td class="right">268435456</td>
<td class="right">65536</td>
<td class="right">8192</td>
<td class="right">256</td>
<td class="right">2</td>
</tr>
<tr>
<td class="right bolded">30</td>
<td class="right">536870912</td>
<td class="right">131072</td>
<td class="right">16384</td>
<td class="right">512</td>
<td class="right">4</td>
</tr>
</tbody>
</table>
<p>(The thirteen days mentioned explicitly in the story are shown in <strong>bold</strong>).</p>
<p>Here&#8217;s the same table, but using exponents to make the powers of two progressions more obvious:</p>
<table class="center" border="1" summary="Rice Received By Day (exponents)">
<caption><strong>Amount of Rice Received By Day (Using Exponents)</strong></caption>
<tbody>
<tr>
<th class="center">Day</th>
<th class="center">Grains</th>
<th class="center">Bowls</th>
<th class="center">Bags</th>
<th class="center">Baskets</th>
<th class="center">Storehouses</th>
</tr>
<tr>
<td class="right bolded">1</td>
<td class="center">2<sup>0</sup></td>
<td class="center grayed">2<sup>-12</sup></td>
<td class="center grayed">2<sup>-15</sup></td>
<td class="center grayed">2<sup>-20</sup></td>
<td class="center grayed">2<sup>-27</sup></td>
</tr>
<tr>
<td class="right bolded">2</td>
<td class="center">2<sup>1</sup></td>
<td class="center grayed">2<sup>-11</sup></td>
<td class="center grayed">2<sup>-14</sup></td>
<td class="center grayed">2<sup>-19</sup></td>
<td class="center grayed">2<sup>-26</sup></td>
</tr>
<tr>
<td class="right bolded">3</td>
<td class="center">2<sup>2</sup></td>
<td class="center grayed">2<sup>-10</sup></td>
<td class="center grayed">2<sup>-13</sup></td>
<td class="center grayed">2<sup>-18</sup></td>
<td class="center grayed">2<sup>-25</sup></td>
</tr>
<tr>
<td class="right">4</td>
<td class="center">2<sup>3</sup></td>
<td class="center grayed">2<sup>-9</sup></td>
<td class="center grayed">2<sup>-12</sup></td>
<td class="center grayed">2<sup>-17</sup></td>
<td class="center grayed">2<sup>-24</sup></td>
</tr>
<tr>
<td class="right">5</td>
<td class="center">2<sup>4</sup></td>
<td class="center grayed">2<sup>-8</sup></td>
<td class="center grayed">2<sup>-11</sup></td>
<td class="center grayed">2<sup>-16</sup></td>
<td class="center grayed">2<sup>-23</sup></td>
</tr>
<tr>
<td class="right">6</td>
<td class="center">2<sup>5</sup></td>
<td class="center grayed">2<sup>-7</sup></td>
<td class="center grayed">2<sup>-10</sup></td>
<td class="center grayed">2<sup>-15</sup></td>
<td class="center grayed">2<sup>-22</sup></td>
</tr>
<tr>
<td class="right">7</td>
<td class="center">2<sup>6</sup></td>
<td class="center grayed">2<sup>-6</sup></td>
<td class="center grayed">2<sup>-9</sup></td>
<td class="center grayed">2<sup>-14</sup></td>
<td class="center grayed">2<sup>-21</sup></td>
</tr>
<tr>
<td class="right">8</td>
<td class="center">2<sup>7</sup></td>
<td class="center grayed">2<sup>-5</sup></td>
<td class="center grayed">2<sup>-8</sup></td>
<td class="center grayed">2<sup>-13</sup></td>
<td class="center grayed">2<sup>-20</sup></td>
</tr>
<tr>
<td class="right bolded">9</td>
<td class="center">2<sup>8</sup></td>
<td class="center grayed">2<sup>-4</sup></td>
<td class="center grayed">2<sup>-7</sup></td>
<td class="center grayed">2<sup>-12</sup></td>
<td class="center grayed">2<sup>-19</sup></td>
</tr>
<tr>
<td class="right">10</td>
<td class="center">2<sup>9</sup></td>
<td class="center grayed">2<sup>-3</sup></td>
<td class="center grayed">2<sup>-6</sup></td>
<td class="center grayed">2<sup>-11</sup></td>
<td class="center grayed">2<sup>-18</sup></td>
</tr>
<tr>
<td class="right">11</td>
<td class="center">2<sup>10</sup></td>
<td class="center grayed">2<sup>-2</sup></td>
<td class="center grayed">2<sup>-5</sup></td>
<td class="center grayed">2<sup>-10</sup></td>
<td class="center grayed">2<sup>-17</sup></td>
</tr>
<tr>
<td class="right bolded">12</td>
<td class="center">2<sup>11</sup></td>
<td class="center grayed">2<sup>-1</sup></td>
<td class="center grayed">2<sup>-4</sup></td>
<td class="center grayed">2<sup>-9</sup></td>
<td class="center grayed">2<sup>-16</sup></td>
</tr>
<tr>
<td class="right bolded">13</td>
<td class="center">2<sup>12</sup></td>
<td class="center">2<sup>0</sup></td>
<td class="center grayed">2<sup>-3</sup></td>
<td class="center grayed">2<sup>-8</sup></td>
<td class="center grayed">2<sup>-15</sup></td>
</tr>
<tr>
<td class="right">14</td>
<td class="center">2<sup>13</sup></td>
<td class="center">2<sup>1</sup></td>
<td class="center grayed">2<sup>-2</sup></td>
<td class="center grayed">2<sup>-7</sup></td>
<td class="center grayed">2<sup>-14</sup></td>
</tr>
<tr>
<td class="right">15</td>
<td class="center">2<sup>14</sup></td>
<td class="center">2<sup>2</sup></td>
<td class="center grayed">2<sup>-1</sup></td>
<td class="center grayed">2<sup>-6</sup></td>
<td class="center grayed">2<sup>-13</sup></td>
</tr>
<tr>
<td class="right bolded">16</td>
<td class="center">2<sup>15</sup></td>
<td class="center">2<sup>3</sup></td>
<td class="center">2<sup>0</sup></td>
<td class="center grayed">2<sup>-5</sup></td>
<td class="center grayed">2<sup>-12</sup></td>
</tr>
<tr>
<td class="right">17</td>
<td class="center">2<sup>16</sup></td>
<td class="center">2<sup>4</sup></td>
<td class="center">2<sup>1</sup></td>
<td class="center grayed">2<sup>-4</sup></td>
<td class="center grayed">2<sup>-11</sup></td>
</tr>
<tr>
<td class="right">18</td>
<td class="center">2<sup>17</sup></td>
<td class="center">2<sup>5</sup></td>
<td class="center">2<sup>2</sup></td>
<td class="center grayed">2<sup>-3</sup></td>
<td class="center grayed">2<sup>-10</sup></td>
</tr>
<tr>
<td class="right">19</td>
<td class="center">2<sup>18</sup></td>
<td class="center">2<sup>6</sup></td>
<td class="center">2<sup>3</sup></td>
<td class="center grayed">2<sup>-2</sup></td>
<td class="center grayed">2<sup>-9</sup></td>
</tr>
<tr>
<td class="right bolded">20</td>
<td class="center">2<sup>19</sup></td>
<td class="center">2<sup>7</sup></td>
<td class="center">2<sup>4</sup></td>
<td class="center grayed">2<sup>-1</sup></td>
<td class="center grayed">2<sup>-8</sup></td>
</tr>
<tr>
<td class="right bolded">21</td>
<td class="center">2<sup>20</sup></td>
<td class="center">2<sup>8</sup></td>
<td class="center">2<sup>5</sup></td>
<td class="center">2<sup>0</sup></td>
<td class="center grayed">2<sup>-7</sup></td>
</tr>
<tr>
<td class="right">22</td>
<td class="center">2<sup>21</sup></td>
<td class="center">2<sup>9</sup></td>
<td class="center">2<sup>6</sup></td>
<td class="center">2<sup>1</sup></td>
<td class="center grayed">2<sup>-6</sup></td>
</tr>
<tr>
<td class="right">23</td>
<td class="center">2<sup>22</sup></td>
<td class="center">2<sup>10</sup></td>
<td class="center">2<sup>7</sup></td>
<td class="center">2<sup>2</sup></td>
<td class="center grayed">2<sup>-5</sup></td>
</tr>
<tr>
<td class="right bolded">24</td>
<td class="center">2<sup>23</sup></td>
<td class="center">2<sup>11</sup></td>
<td class="center">2<sup>8</sup></td>
<td class="center">2<sup>3</sup></td>
<td class="center grayed">2<sup>-4</sup></td>
</tr>
<tr>
<td class="right">25</td>
<td class="center">2<sup>24</sup></td>
<td class="center">2<sup>12</sup></td>
<td class="center">2<sup>9</sup></td>
<td class="center">2<sup>4</sup></td>
<td class="center grayed">2<sup>-3</sup></td>
</tr>
<tr>
<td class="right">26</td>
<td class="center">2<sup>25</sup></td>
<td class="center">2<sup>13</sup></td>
<td class="center">2<sup>10</sup></td>
<td class="center">2<sup>5</sup></td>
<td class="center grayed">2<sup>-2</sup></td>
</tr>
<tr>
<td class="right bolded">27</td>
<td class="center">2<sup>26</sup></td>
<td class="center">2<sup>14</sup></td>
<td class="center">2<sup>11</sup></td>
<td class="center">2<sup>6</sup></td>
<td class="center grayed">2<sup>-1</sup></td>
</tr>
<tr>
<td class="right">28</td>
<td class="center">2<sup>27</sup></td>
<td class="center">2<sup>15</sup></td>
<td class="center">2<sup>12</sup></td>
<td class="center">2<sup>7</sup></td>
<td class="center">2<sup>0</sup></td>
</tr>
<tr>
<td class="right bolded">29</td>
<td class="center">2<sup>28</sup></td>
<td class="center">2<sup>16</sup></td>
<td class="center">2<sup>13</sup></td>
<td class="center">2<sup>8</sup></td>
<td class="center">2<sup>1</sup></td>
</tr>
<tr>
<td class="right bolded">30</td>
<td class="center">2<sup>29</sup></td>
<td class="center">2<sup>17</sup></td>
<td class="center">2<sup>14</sup></td>
<td class="center">2<sup>9</sup></td>
<td class="center">2<sup>2</sup></td>
</tr>
</tbody>
</table>
<p>Finally, here&#8217;s the same information, condensed into simple formulas:</p>
<ul>
<li>Number of <strong>grains</strong> on day d = 2<sup>d-1</sup></li>
<li>Number of <strong>bowls</strong> on day d = 2<sup>d-13</sup></li>
<li>Number of <strong>bags</strong> on day d = 2<sup>d-16</sup></li>
<li>Number of <strong>baskets</strong> on day d = 2<sup>d-21</sup></li>
<li>Number of <strong>storehouses</strong> on day d = 2<sup>d-28</sup></li>
</ul>
<p>These relationships are simple: each measure doubles each day, so the exponent of each power of two increases by one each day. The offset in the exponent of the container formulas shows where each transitions from negative powers of two to nonnegative powers of two.</p>
<h2>Cumulative Rice Received, By Day</h2>
<p>I made a table showing the cumulative number of grains of rice by day, by measure. The amounts are <em>not</em> powers of two, although they follow a pattern, which I&#8217;ll explain below. The table is broken into two parts (to fit on this page), with fractional amounts less than one shown in gray:</p>
<table class="center" border="1" summary="Accumulated Rice By Day, part 1">
<caption><strong>Amount of Rice Accumulated Through Each Day (Part 1: Grains, Bowls, and Bags)</strong></caption>
<tbody>
<tr>
<th class="center">Day</th>
<th class="center">Grains</th>
<th class="center">Bowls</th>
<th class="center">Bags</th>
</tr>
<tr>
<td class="right bolded">1</td>
<td class="right">1</td>
<td class="right grayed">1/4096</td>
<td class="right grayed">1/32768</td>
</tr>
<tr>
<td class="right bolded">2</td>
<td class="right">3</td>
<td class="right grayed">3/4096</td>
<td class="right grayed">3/32768</td>
</tr>
<tr>
<td class="right bolded">3</td>
<td class="right">7</td>
<td class="right grayed">7/4096</td>
<td class="right grayed">7/32768</td>
</tr>
<tr>
<td class="right">4</td>
<td class="right">15</td>
<td class="right grayed">15/4096</td>
<td class="right grayed">15/32768</td>
</tr>
<tr>
<td class="right">5</td>
<td class="right">31</td>
<td class="right grayed">31/4096</td>
<td class="right grayed">31/32768</td>
</tr>
<tr>
<td class="right">6</td>
<td class="right">63</td>
<td class="right grayed">63/4096</td>
<td class="right grayed">63/32768</td>
</tr>
<tr>
<td class="right">7</td>
<td class="right">127</td>
<td class="right grayed">127/4096</td>
<td class="right grayed">127/32768</td>
</tr>
<tr>
<td class="right">8</td>
<td class="right">255</td>
<td class="right grayed">255/4096</td>
<td class="right grayed">255/32768</td>
</tr>
<tr>
<td class="right bolded">9</td>
<td class="right">511</td>
<td class="right grayed">511/4096</td>
<td class="right grayed">511/32768</td>
</tr>
<tr>
<td class="right">10</td>
<td class="right">1023</td>
<td class="right grayed">1023/4096</td>
<td class="right grayed">1023/32768</td>
</tr>
<tr>
<td class="right">11</td>
<td class="right">2047</td>
<td class="right grayed">2047/4096</td>
<td class="right grayed">2047/32768</td>
</tr>
<tr>
<td class="right bolded">12</td>
<td class="right">4095</td>
<td class="right grayed">4095/4096</td>
<td class="right grayed">4095/32768</td>
</tr>
<tr>
<td class="right bolded">13</td>
<td class="right">8191</td>
<td class="right">1 4095/4096</td>
<td class="right grayed">8191/32768</td>
</tr>
<tr>
<td class="right">14</td>
<td class="right">16383</td>
<td class="right">3 4095/4096</td>
<td class="right grayed">16383/32768</td>
</tr>
<tr>
<td class="right">15</td>
<td class="right">32767</td>
<td class="right">7 4095/4096</td>
<td class="right grayed">32767/32768</td>
</tr>
<tr>
<td class="right bolded">16</td>
<td class="right">65535</td>
<td class="right">15 4095/4096</td>
<td class="right">1 32767/32768</td>
</tr>
<tr>
<td class="right">17</td>
<td class="right">131071</td>
<td class="right">31 4095/4096</td>
<td class="right">3 32767/32768</td>
</tr>
<tr>
<td class="right">18</td>
<td class="right">262143</td>
<td class="right">63 4095/4096</td>
<td class="right">7 32767/32768</td>
</tr>
<tr>
<td class="right">19</td>
<td class="right">524287</td>
<td class="right">127 4095/4096</td>
<td class="right">15 32767/32768</td>
</tr>
<tr>
<td class="right bolded">20</td>
<td class="right">1048575</td>
<td class="right">255 4095/4096</td>
<td class="right">31 32767/32768</td>
</tr>
<tr>
<td class="right bolded">21</td>
<td class="right">2097151</td>
<td class="right">511 4095/4096</td>
<td class="right">63 32767/32768</td>
</tr>
<tr>
<td class="right">22</td>
<td class="right">4194303</td>
<td class="right">1023 4095/4096</td>
<td class="right">127 32767/32768</td>
</tr>
<tr>
<td class="right">23</td>
<td class="right">8388607</td>
<td class="right">2047 4095/4096</td>
<td class="right">255 32767/32768</td>
</tr>
<tr>
<td class="right bolded">24</td>
<td class="right">16777215</td>
<td class="right">4095 4095/4096</td>
<td class="right">511 32767/32768</td>
</tr>
<tr>
<td class="right">25</td>
<td class="right">33554431</td>
<td class="right">8191 4095/4096</td>
<td class="right">1023 32767/32768</td>
</tr>
<tr>
<td class="right">26</td>
<td class="right">67108863</td>
<td class="right">16383 4095/4096</td>
<td class="right">2047 32767/32768</td>
</tr>
<tr>
<td class="right bolded">27</td>
<td class="right">134217727</td>
<td class="right">32767 4095/4096</td>
<td class="right">4095 32767/32768</td>
</tr>
<tr>
<td class="right">28</td>
<td class="right">268435455</td>
<td class="right">65535 4095/4096</td>
<td class="right">8191 32767/32768</td>
</tr>
<tr>
<td class="right bolded">29</td>
<td class="right">536870911</td>
<td class="right">131071 4095/4096</td>
<td class="right">16383 32767/32768</td>
</tr>
<tr>
<td class="right bolded">30</td>
<td class="right">1073741823</td>
<td class="right">262143 4095/4096</td>
<td class="right">32767 32767/32768</td>
</tr>
</tbody>
</table>
<table class="center" border="1" summary="Accumulated Rice By Day, part 2">
<caption><strong>Amount of Rice Accumulated Through Each Day (Part 2: Grains, Baskets, and Storehouses)</strong></caption>
<tbody>
<tr>
<th class="center">Day</th>
<th class="center">Grains</th>
<th class="center">Baskets</th>
<th class="center">Storehouses</th>
</tr>
<tr>
<td class="right bolded">1</td>
<td class="right">1</td>
<td class="right grayed">1/1048576</td>
<td class="right grayed">1/134217728</td>
</tr>
<tr>
<td class="right bolded">2</td>
<td class="right">3</td>
<td class="right grayed">3/1048576</td>
<td class="right grayed">3/134217728</td>
</tr>
<tr>
<td class="right bolded">3</td>
<td class="right">7</td>
<td class="right grayed">7/1048576</td>
<td class="right grayed">7/134217728</td>
</tr>
<tr>
<td class="right">4</td>
<td class="right">15</td>
<td class="right grayed">15/1048576</td>
<td class="right grayed">15/134217728</td>
</tr>
<tr>
<td class="right">5</td>
<td class="right">31</td>
<td class="right grayed">31/1048576</td>
<td class="right grayed">31/134217728</td>
</tr>
<tr>
<td class="right">6</td>
<td class="right">63</td>
<td class="right grayed">63/1048576</td>
<td class="right grayed">63/134217728</td>
</tr>
<tr>
<td class="right">7</td>
<td class="right">127</td>
<td class="right grayed">127/1048576</td>
<td class="right grayed">127/134217728</td>
</tr>
<tr>
<td class="right">8</td>
<td class="right">255</td>
<td class="right grayed">255/1048576</td>
<td class="right grayed">255/134217728</td>
</tr>
<tr>
<td class="right bolded">9</td>
<td class="right">511</td>
<td class="right grayed">511/1048576</td>
<td class="right grayed">511/134217728</td>
</tr>
<tr>
<td class="right">10</td>
<td class="right">1023</td>
<td class="right grayed">1023/1048576</td>
<td class="right grayed">1023/134217728</td>
</tr>
<tr>
<td class="right">11</td>
<td class="right">2047</td>
<td class="right grayed">2047/1048576</td>
<td class="right grayed">2047/134217728</td>
</tr>
<tr>
<td class="right bolded">12</td>
<td class="right">4095</td>
<td class="right grayed">4095/1048576</td>
<td class="right grayed">4095/134217728</td>
</tr>
<tr>
<td class="right">13</td>
<td class="right">8191</td>
<td class="right grayed">8191/1048576</td>
<td class="right grayed">8191/134217728</td>
</tr>
<tr>
<td class="right">14</td>
<td class="right">16383</td>
<td class="right grayed">16383/1048576</td>
<td class="right grayed">16383/134217728</td>
</tr>
<tr>
<td class="right">15</td>
<td class="right">32767</td>
<td class="right grayed">32767/1048576</td>
<td class="right grayed">32767/134217728</td>
</tr>
<tr>
<td class="right bolded">16</td>
<td class="right">65535</td>
<td class="right grayed">65535/1048576</td>
<td class="right grayed">65535/134217728</td>
</tr>
<tr>
<td class="right">17</td>
<td class="right">131071</td>
<td class="right grayed">131071/1048576</td>
<td class="right grayed">131071/134217728</td>
</tr>
<tr>
<td class="right">18</td>
<td class="right">262143</td>
<td class="right grayed">262143/1048576</td>
<td class="right grayed">262143/134217728</td>
</tr>
<tr>
<td class="right">19</td>
<td class="right">524287</td>
<td class="right grayed">524287/1048576</td>
<td class="right grayed">524287/134217728</td>
</tr>
<tr>
<td class="right bolded">20</td>
<td class="right">1048575</td>
<td class="right grayed">1048575/1048576</td>
<td class="right grayed">1048575/134217728</td>
</tr>
<tr>
<td class="right">21</td>
<td class="right">2097151</td>
<td class="right">1 1048575/1048576</td>
<td class="right grayed">2097151/134217728</td>
</tr>
<tr>
<td class="right">22</td>
<td class="right">4194303</td>
<td class="right">3 1048575/1048576</td>
<td class="right grayed">4194303/134217728</td>
</tr>
<tr>
<td class="right">23</td>
<td class="right">8388607</td>
<td class="right">7 1048575/1048576</td>
<td class="right grayed">8388607/134217728</td>
</tr>
<tr>
<td class="right bolded">24</td>
<td class="right">16777215</td>
<td class="right">15 1048575/1048576</td>
<td class="right grayed">16777215/134217728</td>
</tr>
<tr>
<td class="right">25</td>
<td class="right">33554431</td>
<td class="right">31 1048575/1048576</td>
<td class="right grayed">33554431/134217728</td>
</tr>
<tr>
<td class="right">26</td>
<td class="right">67108863</td>
<td class="right">63 1048575/1048576</td>
<td class="right grayed">67108863/134217728</td>
</tr>
<tr>
<td class="right bolded">27</td>
<td class="right">134217727</td>
<td class="right">127 1048575/1048576</td>
<td class="right grayed">134217727/134217728</td>
</tr>
<tr>
<td class="right">28</td>
<td class="right">268435455</td>
<td class="right">255 1048575/1048576</td>
<td class="right">1 134217727/134217728</td>
</tr>
<tr>
<td class="right bolded">29</td>
<td class="right">536870911</td>
<td class="right">511 1048575/1048576</td>
<td class="right">3 134217727/134217728</td>
</tr>
<tr>
<td class="right bolded">30</td>
<td class="right">1073741823</td>
<td class="right">1023 1048575/1048576</td>
<td class="right">7 134217727/134217728</td>
</tr>
</tbody>
</table>
<p>The pattern is easier to see if you rewrite the values using exponents, and write mixed numbers as improper fractions: </p>
<table class="center" border="1" summary="Accumulated Rice By Day, Using Exponents">
<caption><strong>Amount of Rice Accumulated Through Each Day, Using Exponents</strong></caption>
<tbody>
<tr>
<th class="center">Day</th>
<th class="center">Grains</th>
<th class="center">Bowls</th>
<th class="center">Bags</th>
<th class="center">Baskets</th>
<th class="center">Storehouses</th>
</tr>
<tr>
<td class="right bolded">1</td>
<td class="center">2<sup>1</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>1</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>1</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>1</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>1</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">2</td>
<td class="center">2<sup>2</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>2</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>2</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>2</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>2</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">3</td>
<td class="center">2<sup>3</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>3</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>3</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>3</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>3</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">4</td>
<td class="center">2<sup>4</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>4</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>4</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>4</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>4</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">5</td>
<td class="center">2<sup>5</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>5</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>5</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>5</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>5</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">6</td>
<td class="center">2<sup>6</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>6</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>6</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>6</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>6</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">7</td>
<td class="center">2<sup>7</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>7</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>7</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>7</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>7</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">8</td>
<td class="center">2<sup>8</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>8</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>8</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>8</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>8</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">9</td>
<td class="center">2<sup>9</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>9</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>9</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>9</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>9</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">10</td>
<td class="center">2<sup>10</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>10</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>10</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>10</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>10</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">11</td>
<td class="center">2<sup>11</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>11</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>11</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>11</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>11</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">12</td>
<td class="center">2<sup>12</sup> &#8211; 1</td>
<td class="center grayed">(2<sup>12</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>12</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>12</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>12</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">13</td>
<td class="center">2<sup>13</sup> &#8211; 1</td>
<td class="center">(2<sup>13</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>13</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>13</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>13</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">14</td>
<td class="center">2<sup>14</sup> &#8211; 1</td>
<td class="center">(2<sup>14</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>14</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>14</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>14</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">15</td>
<td class="center">2<sup>15</sup> &#8211; 1</td>
<td class="center">(2<sup>15</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center grayed">(2<sup>15</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>15</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>15</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">16</td>
<td class="center">2<sup>16</sup> &#8211; 1</td>
<td class="center">(2<sup>16</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>16</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>16</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>16</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">17</td>
<td class="center">2<sup>17</sup> &#8211; 1</td>
<td class="center">(2<sup>17</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>17</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>17</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>17</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">18</td>
<td class="center">2<sup>18</sup> &#8211; 1</td>
<td class="center">(2<sup>18</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>18</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>18</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>18</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">19</td>
<td class="center">2<sup>19</sup> &#8211; 1</td>
<td class="center">(2<sup>19</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>19</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>19</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>19</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">20</td>
<td class="center">2<sup>20</sup> &#8211; 1</td>
<td class="center">(2<sup>20</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>20</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center grayed">(2<sup>20</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>20</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">21</td>
<td class="center">2<sup>21</sup> &#8211; 1</td>
<td class="center">(2<sup>21</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>21</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center">(2<sup>21</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>21</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">22</td>
<td class="center">2<sup>22</sup> &#8211; 1</td>
<td class="center">(2<sup>22</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>22</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center">(2<sup>22</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>22</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">23</td>
<td class="center">2<sup>23</sup> &#8211; 1</td>
<td class="center">(2<sup>23</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>23</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center">(2<sup>23</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>23</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">24</td>
<td class="center">2<sup>24</sup> &#8211; 1</td>
<td class="center">(2<sup>24</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>24</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center">(2<sup>24</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>24</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">25</td>
<td class="center">2<sup>25</sup> &#8211; 1</td>
<td class="center">(2<sup>25</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>25</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center">(2<sup>25</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>25</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">26</td>
<td class="center">2<sup>26</sup> &#8211; 1</td>
<td class="center">(2<sup>26</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>26</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center">(2<sup>26</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>26</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">27</td>
<td class="center">2<sup>27</sup> &#8211; 1</td>
<td class="center">(2<sup>27</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>27</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center">(2<sup>27</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center grayed">(2<sup>27</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right">28</td>
<td class="center">2<sup>28</sup> &#8211; 1</td>
<td class="center">(2<sup>28</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>28</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center">(2<sup>28</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center">(2<sup>28</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">29</td>
<td class="center">2<sup>29</sup> &#8211; 1</td>
<td class="center">(2<sup>29</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>29</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center">(2<sup>29</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center">(2<sup>29</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
<tr>
<td class="right bolded">30</td>
<td class="center">2<sup>30</sup> &#8211; 1</td>
<td class="center">(2<sup>30</sup> &#8211; 1)/2<sup>12</sup></td>
<td class="center">(2<sup>30</sup> &#8211; 1)/2<sup>15</sup></td>
<td class="center">(2<sup>30</sup> &#8211; 1)/2<sup>20</sup></td>
<td class="center">(2<sup>30</sup> &#8211; 1)/2<sup>27</sup></td>
</tr>
</tbody>
</table>
<p>Each value is simply the number of grains of rice accumulated, divided by the size of the corresponding measure in grains:</p>
<ul>
<li>Number of <strong>grains</strong> through day d: 2<sup>d</sup> &#8211; 1</li>
<li>Number of <strong>bowls</strong> through day d: (2<sup>d</sup> &#8211; 1)/2<sup>12</sup></li>
<li>Number of <strong>bags</strong> through day d: (2<sup>d</sup> &#8211; 1)/2<sup>15</sup></li>
<li>Number of <strong>baskets</strong> through day d: (2<sup>d</sup> &#8211; 1)/2<sup>20</sup></li>
<li>Number of <strong>storehouses</strong> through day d: (2<sup>d</sup> &#8211; 1)/2<sup>27</sup></li>
</ul>
<p>The sum of grains is a <strong>geometric series</strong>, being the sum of numbers from a geometric sequence &#8212; in this case, the first d nonnegative powers of two. Conveniently, we don&#8217;t need to add them to know their total; this well-known formula gives their sum directly:</p>
<p class="center"><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/1073741823-grains-of-rice/9e25e3afd309d77c937a834031580c55.png' alt='\mbox{\footnotesize{\displaystyle{\sum_{i=0}^{d-1}2^i = 2^{d} \;{-}\;1}}}'/></p>
<p>(Numbers of the form 2<sup>n</sup> &#8211; 1 are called <a title="Read Wolfram article &ldquo;Mersenne Number&rdquo;" href="http://mathworld.wolfram.com/MersenneNumber.html">Mersenne numbers</a>.)</p>
<p>For example, on day 15, 2<sup>15</sup> &#8211; 1 = 32767 grains of rice have accumulated, an amount that would fill (2<sup>15</sup> &#8211; 1)/2<sup>12</sup> = 32767/4096 = 7 4095/4096 bowls.</p>
<h3>The Formulas for Representation as Mixed Numbers</h3>
<p>The simple formulas above, expressed as improper fractions, hide the pattern that lies in the mixed number representation of the values of the containers.</p>
<p>Each value is a sum of consecutive powers of two. Some values are sums of negative powers of two, and some are sums of both negative and nonnegative powers of two. Values for measures that start out accumulating in fractional units (each measure except grains) are sums of negative powers of two. At some point, when whole number units start to add in, sums of nonnegative powers of two become part of the total. This is when the value becomes an improper fraction, or mixed number. </p>
<p>These formulas take into account the point at which the values become improper fractions, but expressing them as mixed numbers:</p>
<ul>
<li>Number of <strong>bowls</strong> through day d:
<p>If day &le; 12: (2<sup>d</sup> &#8211; 1)/2<sup>12</sup></p>
<p>If day &gt; 12: (2<sup>d-12</sup> &#8211; 1) + (2<sup>12</sup> &#8211; 1)/2<sup>12</sup></p>
</li>
<li>Number of <strong>bags</strong> through day d:
<p>If day &le; 15: (2<sup>d</sup> &#8211; 1)/2<sup>15</sup></p>
<p>If day &gt; 15: (2<sup>d-15</sup> &#8211; 1) + (2<sup>15</sup> &#8211; 1)/2<sup>15</sup></p>
</li>
<li>Number of <strong>baskets</strong> through day d:
<p>If day &le; 20: (2<sup>d</sup> &#8211; 1)/2<sup>20</sup></p>
<p>If day &gt; 20: (2<sup>d-20</sup> &#8211; 1) + (2<sup>20</sup> &#8211; 1)/2<sup>20</sup></p>
</li>
<li>Number of <strong>storehouses</strong> through day d:
<p>If day &le; 27: (2<sup>d</sup> &#8211; 1)/2<sup>27</sup></p>
<p>If day &gt; 27: (2<sup>d-27</sup> &#8211; 1) + (2<sup>27</sup> &#8211; 1)/2<sup>27</sup></p>
</li>
</ul>
<p>Fractional values accumulate as a Mersenne number over a power of two; once whole number values begin to add in, the accumulated fractional part remains unchanged while the whole number part accumulates as a Mersenne number.</p>
<p>It&#8217;s easy to show that the mixed number formulas are equivalent to the improper fraction formulas. For example, take the mixed number formula for bowls after day 12: </p>
<p class="center"><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/1073741823-grains-of-rice/d0ca19fb724f77605a414bdd6229b8e8.png' alt='\mbox{\footnotesize{\displaystyle{(2^{d-12} \;{-}\;1) + \frac{(2^{12} \;{-}\;1)}{2^{12}}}}}'/></p>
<p>You can rewrite this, using simple algebra and the <a title="Read Rick Regan's Article &ldquo;Composing Powers of Two Using The Laws of Exponents&rdquo;" href="http://www.exploringbinary.com/composing-powers-of-two-using-the-laws-of-exponents/">laws of exponents</a>, as follows:</p>
<p class="center"><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/1073741823-grains-of-rice/b37787731b30788e31a83ef7bca6cbdf.png' alt='\mbox{\footnotesize{\displaystyle{= \frac{(2^{d-12} \;{-}\;1)\cdot{2^{12}} + (2^{12} \;{-}\;1)}{2^{12}}}}}'/></p>
<p class="center"><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/1073741823-grains-of-rice/4e6f8f1563e2067b370b1dd22e079d41.png' alt='\mbox{\footnotesize{\displaystyle{= \frac{(2^{d} \;{-}\;2^{12}) + (2^{12} \;{-}\;1)}{2^{12}}}}}'/></p>
<p class="center"><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/1073741823-grains-of-rice/392d0be797aa05de4ffe5f9d22f78936.png' alt='\mbox{\footnotesize{\displaystyle{= \frac{2^{d} \;{-}\;1}{2^{12}}}}}'/></p>
<p>This is the the same formula as for before day 12, and thus the same formula for all days.</p>
<h2>In the Classroom</h2>
<p>This is a good story upon which to base a math lesson, and you can vary the mathematical sophistication according to grade level. I read it to first and third graders, so I had to keep it simple. My goal was to show how numbers grow through doubling, and to introduce place value of large numbers.</p>
<h3>First Graders</h3>
<p>When I read the story to a first grade class, I got lots of &ldquo;oohs&rdquo; and &ldquo;aahs&rdquo; whenever I read a big number from the text and whenever they saw an illustration of the many animals needed to transport the rice. At the end of the story, I wrote 1,073,741,823 on the board to show them how it looks in numerals. Although I knew they&#8217;d only been taught up to the hundreds place, I went through each place and named it. I finished by saying &#8220;when you get to third grade I can explain the math a little more.&#8221;</p>
<h3>Third Graders</h3>
<p>For the third grade class, I read the story and spent about fifteen minutes afterwards discussing the numbers. First I wrote 1,073,741,823 on the board and went through the places. Even though they had been taught only up to the thousands place, most of them knew to the billions place (and beyond). Next, I asked them to say the number in words, and many had difficulty &#8212; particularly the &ldquo;seven-hundred forty one thousand&rdquo; part (I don&#8217;t know why it was harder than &ldquo;seventy-three million&rdquo; &#8212; I would have thought the zero in the hundred millions place would be confusing).</p>
<p>Next, I wrote the number 1 and had them tell me the next numbers in the sequence. A couple of kids answered correctly up to 8,192 (2<sup>14</sup>). When I asked one boy if he had them memorized, he said &ldquo;No, I can add them in my head.&rdquo;</p>
<p>I continued the sequence using a pocket calculator. I had the students take turns computing the next number with it (they found it very hard to recite the numbers back to me, because there were no commas). By design, one unlucky kid had 2<sup>27</sup> (134,217,728) for his turn, which caused the calculator to overflow. I told the class that the numbers get so big that you need a computer to figure them out.</p>
<p>At the end, I referred to these numbers as &ldquo;powers of two,&rdquo; and told them they would be useful someday if they wanted to work with computers (can you blame me for plugging my profession?).</p>
<p>One boy asked a good question: &ldquo;what if you got 20 grains every minute for 30 days &#8212; would that be more?&rdquo; I said &ldquo;Great question: I think you&#8217;d still get more by doubling though.&rdquo; The calculator showed him this to be true &#8212; his method accumulated only 864,000 grains.</p>
<h3>Lesson Plan Resources</h3>
<p>If you search the Internet for &ldquo;One Grain of Rice&rdquo; you&#8217;ll find other ideas on how to incorporate this story into a math lesson. For example, <a title="See University of Texas at Austin Charles A. Dana Center lesson plan for &ldquo;One Grain of Rice&rdquo;" href="http://www.utdanacenter.org/highered/alg1/downloads/IV-B-CourseContent-AlgI/AlgI_3-3-2.pdf">this worksheet</a> uses graphs and logarithms.</p>
<h2>Errors in the Story</h2>
<p>I found two errors and one inconsistency in the story:</p>
<h3>Before the Rice Is Delivered</h3>
<p>Rani describes her plan for receiving the rice as follows:</p>
<blockquote><p>&ldquo;Today, you will give me a single grain of rice. Then, each day for thirty days you will give me double the rice you gave me the day before. Thus, tomorrow you will give me two grains of rice, the next day four grains of rice, and so on for thirty days.&rdquo;</p></blockquote>
<p>The doubling occurs for <strong>twenty-nine</strong> days, not thirty days.</p>
<h3>On Day 16</h3>
<p>On day 16 it says</p>
<blockquote><p>&ldquo;On the sixteenth day, Rani was presented with a bag containing thirty-two thousand, seven hundred and sixty-eight grains of rice. All together she had enough rice for two full bags&rdquo;</p></blockquote>
<p>Through day 16 she had 65,535 grains of rice, one grain <strong>less</strong> than two full bags; she actually had 1 32767/32768  = 1.999969482421875 bags.</p>
<h3>On Day 9</h3>
<p>On day 9 it says</p>
<blockquote><p>&ldquo;On the ninth day, Rani was presented with two hundred and fifty-six grains of rice. She had received in all five hundred and eleven grains of rice, only enough for a small handful.&rdquo;</p></blockquote>
<p>Technically, there&#8217;s nothing wrong with this, but the measure &ldquo;small handful&rdquo; &#8212; 511 grains &#8212; is <strong>not a power of two</strong>. It doesn&#8217;t fit neatly into the scheme of other units (and hence is why I didn&#8217;t include it in the tables).</p>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/1073741823-grains-of-rice/">1,073,741,823 Grains of Rice</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/1073741823-grains-of-rice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ending Digits of Powers of Five Form a Binary Tree</title>
		<link>http://www.exploringbinary.com/ending-digits-of-powers-of-five-form-a-binary-tree/</link>
		<comments>http://www.exploringbinary.com/ending-digits-of-powers-of-five-form-a-binary-tree/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 15:50:03 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Algebra]]></category>
		<category><![CDATA[Exponents]]></category>
		<category><![CDATA[Modular arithmetic]]></category>
		<category><![CDATA[Proof]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=273</guid>
		<description><![CDATA[In my article &#8220;Patterns in the Last Digits of the Positive Powers of Five&#8221; I showed that the cycles of ending digits of the positive powers of five could be represented with a binary tree: The tree layout shows that certain pairs of ending digits are related, and that these pairs differ by five in [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/ending-digits-of-powers-of-five-form-a-binary-tree/">Ending Digits of Powers of Five Form a Binary Tree</a></p>
]]></description>
			<content:encoded><![CDATA[<p>In my article &ldquo;<a title="Read Rick Regan's Article &ldquo;Patterns in the Last Digits of the Positive Powers of Five&rdquo;" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/">Patterns in the Last Digits of the Positive Powers of Five</a>&rdquo; I showed that the cycles of ending digits of the positive powers of five could be represented with a binary tree:</p>
<div class="wp-caption aligncenter" style="width: 529px"><img src="http://www.exploringbinary.com/wp-content/uploads/PO5Tree.v2.digits.png" alt="Binary Tree Showing Nested Ending Digit Patterns of the Positive Powers of 5" width="519" height="342"/><p class="wp-caption-text">Binary Tree Showing Nested Ending Digit Patterns of the Positive Powers of Five</p></div>
<p>The tree layout shows that certain pairs of ending digits are related, and that <strong>these pairs differ by five in their starting digits</strong>. I will show why this is true.</p>
<p><span id="more-273"></span></p>
<h2>Ending Digit Cycles</h2>
<p>The ending digit cycles of the positive powers of five can be determined by <a title="Read Rick Regan's Article &ldquo;Patterns in the Last Digits of the Positive Powers of Five&rdquo;" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/">incremental calculation modulo powers of ten</a>. The resulting calculations can be tabulated as follows:</p>
<ul>
<li><strong>1-digit endings</strong>
<ul>
<li><strong>5<sup>1</sup></strong>: 5</li>
</ul>
</li>
<li><strong>2-digit endings</strong>
<ul>
<li><strong>5<sup>2</sup></strong>: 25</li>
</ul>
</li>
<li><strong>3-digit endings</strong>
<ul>
<li><strong>5<sup>3</sup></strong>: 125</li>
<li>5<sup>4</sup>: 625</li>
</ul>
</li>
<li><strong>4-digit endings</strong>
<ul>
<li><strong>5<sup>4</sup></strong>: 0625</li>
<li>5<sup>5</sup>: 3125</li>
<li>5<sup>6</sup>: 5625</li>
<li>5<sup>7</sup>: 8125</li>
</ul>
</li>
<li><strong>5-digit endings</strong>
<ul>
<li><strong>5<sup>5</sup></strong>: 03125</li>
<li>5<sup>6</sup>: 15625</li>
<li>5<sup>7</sup>: 78125</li>
<li>5<sup>8</sup>: 90625</li>
<li>5<sup>9</sup>: 53125</li>
<li>5<sup>10</sup>: 65625</li>
<li>5<sup>11</sup>: 28125</li>
<li>5<sup>12</sup>: 40625</li>
</ul>
</li>
<li><strong>&#8230;</strong></li>
</ul>
<p>Each group of m-digit endings repeats in a cycle. <a title="Read Rick Regan's Article &ldquo;Cycle Length of Powers of Five Mod Powers of Ten&rdquo;" href="http://www.exploringbinary.com/cycle-length-of-powers-of-five-mod-powers-of-ten/">Each cycle is a power of two in length, and for m &ge; 2, equals 2<sup>m-2</sup></a>.</p>
<p>Ending digits are labeled with specific powers of five: those that make up the first occurrence of each cycle. Each cycle &#8212; from the 3-digit endings on &#8212; contains the ending digits of 5<sup>m</sup> through 5<sup>(m+2<sup>m-2</sup>-1)</sup>.</p>
<h2>Ending Digit Cycles In Tree Form</h2>
<p>The pairing of ending digits in the binary tree shows a relationship between endings in successive cycles; in particular, for level 3 and higher:</p>
<ul>
<li>Each pair of m digit endings has a common m-1 digit suffix.</li>
<li>The starting digits of each pair of m digit endings differ by five.</li>
</ul>
<h2>Why Pairs of Siblings Have the Same Suffix</h2>
<p>Why is there always a pair of siblings, and why do siblings match up as they do? The answer lies in the nesting of power of two sized cycles of ending digits. For example, the last four digits repeat in a cycle of four, and the last five digits repeat in a cycle of eight. To form the eight unique five digit endings, the set of four digit endings must be repeated; duplicate four digit endings will have different starting digits prefixed.</p>
<p>Endings with the same suffix are a half cycle length apart, and are paired as siblings. For example, in the length eight cycle of five ending digits, the following endings are paired: 1st and 5th; 2nd and 6th; 3rd and 7th; 4th and 8th. </p>
<p>In terms of powers of five, sibling pairs differ in their exponents by half a cycle length. You can see this by looking at the underlying powers of five in the tree: </p>
<div class="wp-caption aligncenter" style="width: 534px"><img src="http://www.exploringbinary.com/wp-content/uploads/PO5Tree.v2.powers.png" alt="Binary Tree Showing Powers of 5 Corresponding to Ending Digits" width="524" height="354"/><p class="wp-caption-text">Binary Tree Showing Powers of Five Corresponding to Ending Digits</p></div>
<h2>Why the Starting Digits of Siblings Differ by Five</h2>
<p>To show why the starting digits of siblings differ by five, let&#8217;s look at an example. In level 5 of the tree &#8212; the 5-digit endings &#8212; let&#8217;s compute the difference between each pair of powers of five (I&#8217;ll go in cycle order, not in tree order):</p>
<ul>
<li>5<sup>9</sup> &#8211; 5<sup>5</sup> = 1950000</li>
<li>5<sup>10</sup> &#8211; 5<sup>6</sup> = 9750000</li>
<li>5<sup>11</sup> &#8211; 5<sup>7</sup> = 48750000</li>
<li>5<sup>12</sup> &#8211; 5<sup>8</sup> = 243750000</li>
</ul>
<p>You can see that each differs by five in their fifth digit &#8212; the algebra behind the subtraction shows why:</p>
<ul>
<li>5<sup>9</sup> &#8211; 5<sup>5</sup> = 5<sup>5</sup>(5<sup>4</sup> &#8211; 1) = 5<sup>0</sup>&middot;<strong>5<sup>5</sup>(5<sup>4</sup> &#8211; 1)</strong></li>
<li>5<sup>10</sup> &#8211; 5<sup>6</sup> = 5<sup>6</sup>(5<sup>4</sup> &#8211; 1) = 5<sup>1</sup>&middot;<strong>5<sup>5</sup>(5<sup>4</sup> &#8211; 1)</strong></li>
<li>5<sup>11</sup> &#8211; 5<sup>7</sup> = 5<sup>7</sup>(5<sup>4</sup> &#8211; 1) = 5<sup>2</sup>&middot;<strong>5<sup>5</sup>(5<sup>4</sup> &#8211; 1)</strong></li>
<li>5<sup>12</sup> &#8211; 5<sup>8</sup> = 5<sup>8</sup>(5<sup>4</sup> &#8211; 1) = 5<sup>3</sup>&middot;<strong>5<sup>5</sup>(5<sup>4</sup> &#8211; 1)</strong></li>
</ul>
<p>Let&#8217;s analyze these expressions by evaluating them in three stages:</p>
<ol>
<li><strong>5<sup>4</sup> &#8211; 1</strong>
<p>This expression has a factor of 2<sup>4</sup>. I&#8217;ve shown that <a title="Read Rick Regan's Article &ldquo;Cycle Length of Powers of Five Mod Powers of Ten&rdquo;" href="http://www.exploringbinary.com/cycle-length-of-powers-of-five-mod-powers-of-ten/">5<sup>2<sup>n</sup></sup> &#8211; 1 has exactly n+2 factors of 2</a>; that is, a factor of 2<sup>n+2</sup>.</p>
</li>
<li><strong>5<sup>5</sup>(5<sup>4</sup> &#8211; 1)</strong>
<p>This expression has a factor of 5<sup>5</sup>&middot;2<sup>4</sup> = 5&middot;10<sup>4</sup> = 50000.</p>
</li>
<li><strong>5<sup>i</sup>&middot;5<sup>5</sup>(5<sup>4</sup> &#8211; 1), 0 &le; i &le; 3</strong>
<p>This expression ends in 50000. For i &gt; 0, <a title="Read Rick Regan's Article &ldquo;Patterns in the Last Digits of the Positive Powers of Five&rdquo;" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/">5<sup>i</sup> ends in the digit 5</a>; for i = 0, 5<sup>i</sup> = 1. In either case, multiplying by 5<sup>i</sup> leaves the 5 in the fifth digit unchanged.</p>
</li>
</ol>
<h3>Generalizing</h3>
<p>The example generalizes to show that every pair of endings in <em>every</em> level m of the tree, m &ge; 3, differ by 5 in their starting digits:</p>
<ul>
<li>Cycle length is 2<sup>m-2</sup></li>
<li>Level m includes the powers of five 5<sup>m</sup> through 5<sup>(m+2<sup>m-2</sup>-1)</sup></li>
<li>Siblings are the powers of five p and p&middot;5<sup>2<sup>m-3</sup></sup></li>
<li>The difference between each sibling pair is 5<sup>i</sup>&middot;5<sup>m</sup>&middot;(5<sup>2<sup>m-3</sup></sup> &#8211; 1), for each i between 0 and 2<sup>m-3</sup> &#8211; 1</li>
<li>The factor 5<sup>2<sup>m-3</sup></sup> &#8211; 1 itself has a factor of 2<sup>m-1</sup></li>
<li>The factor 5<sup>m</sup>&middot;(5<sup>2<sup>m-3</sup></sup> &#8211; 1) itself has a factor of 5<sup>m</sup>&middot;2<sup>m-1</sup> = 5&middot;10<sup>m-1</sup></li>
<li>5&middot;10<sup>m-1</sup> is an m-digit number consisting of the digit 5 followed by m-1 zeros</li>
<li>The factor 5<sup>i</sup> leaves the last m digits unchanged: the digit 5 followed by m-1 zeros</li>
</ul>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/ending-digits-of-powers-of-five-form-a-binary-tree/">Ending Digits of Powers of Five Form a Binary Tree</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/ending-digits-of-powers-of-five-form-a-binary-tree/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cycle Length of Powers of Five Mod Powers of Ten</title>
		<link>http://www.exploringbinary.com/cycle-length-of-powers-of-five-mod-powers-of-ten/</link>
		<comments>http://www.exploringbinary.com/cycle-length-of-powers-of-five-mod-powers-of-ten/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 17:37:22 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Algebra]]></category>
		<category><![CDATA[Exponents]]></category>
		<category><![CDATA[Modular arithmetic]]></category>
		<category><![CDATA[Proof]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=263</guid>
		<description><![CDATA[In my article &#8220;Patterns in the Last Digits of the Positive Powers of Five&#8221; I noted that the positive powers of five modulo 10m cycle with period 2m-2, m &#8805; 2, starting at 5m. In this article, I&#8217;ll present my proof, which has two parts: Part 1 shows that the powers of five mod 2m [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/cycle-length-of-powers-of-five-mod-powers-of-ten/">Cycle Length of Powers of Five Mod Powers of Ten</a></p>
]]></description>
			<content:encoded><![CDATA[<p>In my article <a title="Read Rick Regan's Article &ldquo;Patterns in the Last Digits of the Positive Powers of Five&rdquo;" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/">&ldquo;Patterns in the Last Digits of the Positive Powers of Five&rdquo;</a> I noted that the positive powers of five modulo 10<sup>m</sup> cycle with period 2<sup>m-2</sup>, m &ge; 2, starting at 5<sup>m</sup>. In this article, I&#8217;ll present my proof, which has two parts:</p>
<ul>
<li>Part 1 shows that the powers of five <strong>mod 2<sup>m</sup></strong> cycle with period 2<sup>m-2</sup>,  m &ge; 2, <strong>starting at 5<sup>0</sup></strong>.</li>
<li>Part 2 shows that the powers of five <strong>mod 10<sup>m</sup></strong> cycle with the same period as the powers of five mod 2<sup>m</sup>, <strong>starting at 5<sup>m</sup></strong>.</li>
</ul>
<p>The highlight of my proof is in part 1, where I derive a formula to show that the period, or <a title="Wikipedia article on multiplicative order" href="http://en.wikipedia.org/wiki/Multiplicative_order">order</a>, of 5 mod 2<sup>m</sup> is 2<sup>m-2</sup>. While it is in general not possible to derive a formula for the order of a number, I&#8217;ll show it <em>is</em> possible for the powers of five mod 2<sup>m</sup> &#8212; <strong>due to a hidden, binary structure I&#8217;ve uncovered</strong>.</p>
<p><span id="more-263"></span>To understand the proof, you&#8217;ll need to know some algebra and the basics of modular arithmetic.</p>
<h2>Part 1: Period mod 2<sup>m</sup> is 2<sup>m-2</sup></h2>
<p>Part 1 shows that the order of 5 mod 2<sup>m</sup> is 2<sup>m-2</sup>. I break it into three steps, showing that</p>
<ul>
<li><strong>The order of 5 mod 2<sup>m</sup> is a power of two</strong>. This constrains the values for the order so that only expressions of the form 5<sup>2<sup>n</sup></sup> &#8211; 1 need be considered.</li>
<li><strong>5<sup>2<sup>n</sup></sup> &#8211; 1 can be factored to isolate its factors of two</strong>. This is my key insight, made possible by recursive factoring of differences of squares.</li>
<li><strong>5<sup>2<sup>n</sup></sup> &#8211; 1 is divisible by 2<sup>n+2</sup></strong>. This shows that the order of 5 mod 2<sup>n+2</sup> is 2<sup>n</sup>, or equivalently, that the order of 5 mod 2<sup>m</sup> is 2<sup>m-2</sup>.</li>
</ul>
<p>In addition, I show that the powers of five mod 2<sup>m</sup> cycle starting at 5<sup>0</sup>; this is important because it will show that the cycle mod 10<sup>m</sup> always starts after the cycle mod 2<sup>m</sup>.</p>
<h3>The Order of 5 mod 2<sup>m</sup> is a Power of Two</h3>
<p>The order of a mod b is related to <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/35e45b0c464ebbf22f8db5e5404c1af1.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (b)}}}'/>, so let&#8217;s start there. <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/35e45b0c464ebbf22f8db5e5404c1af1.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (b)}}}'/> is Euler&#8217;s phi function, the number of positive integers less than or equal to b that are relatively prime to b (for b a power of two, this is just the count of the odd numbers less than b). We want to compute <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/3904e07c4fb197326b638bb5badf1cbc.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (2^m)}}}'/>, which we can do with this <a title="Wikipedia article that shows the formula for Euler's Phi Function" href="http://en.wikipedia.org/wiki/Euler%27s_totient_function#Computing_Euler.27s_function">simple formula</a>: <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/b00cb65570b30fb2762cf72221133b28.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (p^m) = (p \,$-$ 1) \cdot p^{m\,\textnormal{-}1}}}}'/>. For p=2, this gives <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/3904e07c4fb197326b638bb5badf1cbc.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (2^m)}}}'/> = 2<sup>m-1</sup>. </p>
<p>The <a title="Wikipedia article on multiplicative order" href="http://en.wikipedia.org/wiki/Multiplicative_order">order of <em>a</em> mod <em>b</em> must divide <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/35e45b0c464ebbf22f8db5e5404c1af1.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (b)}}}'/></a>, so the order of the powers of five mod 2<sup>m</sup> must divide <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/3904e07c4fb197326b638bb5badf1cbc.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (2^m)}}}'/>, or 2<sup>m-1</sup>. In other words, the order must be a power of two &#8212; a power of two less than or equal to 2<sup>m-1</sup> to be specific &#8212; because the divisors of a positive power of two are all the positive powers of two less than or equal to it. </p>
<p>Let 2<sup>e</sup> represent any of the candidates for the order of 5 mod 2<sup>m</sup>: 1, 2, 4, 8, &#8230; , 2<sup>m-2</sup>, 2<sup>m-1</sup>. By definition, if the order is 2<sup>e</sup>, <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/57178b9f53f3cfc6e4b6eefd30d0ee32.png' alt='\mbox{\footnotesize{\displaystyle{5^{2^e} \equiv 1 \pmod{2^m}}}}'/>, or equivalently, <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/2b7d384155f2d5c268e73885167820f0.png' alt='\mbox{\footnotesize{\displaystyle{5^{2^e} \,$-$ 1 \equiv 0 \pmod{2^m}}}}'/>. That is, 5<sup>2<sup>e</sup></sup> &#8211; 1 is divisible by 2<sup>m</sup>. Now all we have to do is figure out which e makes this true.</p>
<h3>5<sup>2<sup>n</sup></sup> &#8211; 1 Can Be Factored to Isolate its Factors of Two</h3>
<p>You can factor 5<sup>2<sup>n</sup></sup> &#8211; 1 into (5<sup>2<sup>n/2</sup></sup> + 1)(5<sup>2<sup>n/2</sup></sup> &#8211; 1), since it is a difference of two squares. You can factor 5<sup>2<sup>n/2</sup></sup> &#8211; 1 similarly, into (5<sup>2<sup>n/4</sup></sup> + 1)(5<sup>2<sup>n/4</sup></sup> &#8211; 1). You can do this n times, since log<sub>2</sub>(2<sup>n</sup>) = n. Here&#8217;s an example:</p>
<ol>
<li>5<sup>16</sup> &#8211; 1 = (5<sup>8</sup> + 1)(5<sup>8</sup> &#8211; 1)</li>
<li>5<sup>8</sup> &#8211; 1 = (5<sup>4</sup> + 1)(5<sup>4</sup> &#8211; 1)</li>
<li>5<sup>4</sup> &#8211; 1  = (5<sup>2</sup> + 1)(5<sup>2</sup> &#8211; 1)</li>
<li>5<sup>2</sup> &#8211; 1  = (5<sup>1</sup> + 1)(5<sup>1</sup> &#8211; 1)</li>
<li>5<sup>1</sup> &#8211; 1  = 4</li>
</ol>
<div class="wp-caption aligncenter" style="width: 330px"><img src="http://www.exploringbinary.com/wp-content/uploads/PO5Factors.jpg" alt="Recursive Factoring of Differences of Squares" width="320" height="252"/><p class="wp-caption-text">Recursive Factoring of Differences of Squares</p></div>
<p>Combining these recursively you get 5<sup>16</sup> &#8211; 1 = 4(5<sup>1</sup> + 1)(5<sup>2</sup> + 1)(5<sup>4</sup> + 1)(5<sup>8</sup> + 1).</p>
<p>This generalizes to 5<sup>2<sup>n</sup></sup> &#8211; 1 = 4(5<sup>1</sup> + 1)(5<sup>2</sup> + 1)(5<sup>4</sup> + 1)&middot;&middot;&middot;(5<sup>2<sup>n/2</sup></sup> + 1).</p>
<p>There is a factor of two in each 5<sup>2<sup>f</sup></sup> + 1, as I&#8217;ll show in the next section.</p>
<h3>5<sup>2<sup>n</sup></sup> &#8211; 1 is divisible by 2<sup>n+2</sup></h3>
<p>The factor of four in the factored expression shows there are at least two factors of two in 5<sup>2<sup>n</sup></sup> &#8211; 1. There is also exactly one factor of two in each of the factors 5<sup>2<sup>f</sup></sup> + 1. I&#8217;ll show it in two steps:</p>
<ul>
<li><strong>5<sup>2<sup>f</sup></sup> + 1 is divisible by 2</strong>.
<p><a title="Read Rick Regan's Article &ldquo;Patterns in the Last Digits of the Positive Powers of Five&rdquo;" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/">Every positive power of five ends in 5</a>, so it is odd. This means 5<sup>2<sup>f</sup></sup> + 1 is even, meaning it&#8217;s divisible by 2.</p>
</li>
<li><strong>5<sup>2<sup>f</sup></sup> + 1 is not divisible by any power of two greater than 2</strong>.
<p>To show this, it suffices to show that 5<sup>2<sup>f</sup></sup> + 1 is not divisible by 4. If it&#8217;s not divisible by 4, it&#8217;s not divisible by any higher power of two (because the divisors of a positive power of two are all positive powers of two less than or equal to it). So if 2<sup>2</sup> is not a factor, 2<sup>s</sup>, s &gt; 1, is not a factor.</p>
<p>Let&#8217;s show 5<sup>2<sup>f</sup></sup> + 1 is not divisible by 4 by breaking it in two cases:</p>
<ul>
<li><strong>5<sup>2<sup>0</sup></sup> + 1</strong>. 5<sup>1</sup> + 1 = 6, which obviously is not divisible by 4.</li>
<li><strong>5<sup>2<sup>f</sup></sup> + 1, f &ge; 1</strong>. <a title="Read Rick Regan's Article &ldquo;Patterns in the Last Digits of the Positive Powers of Five&rdquo;" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/">5<sup>2<sup>f</sup></sup> ends in 25</a>, so 5<sup>2<sup>f</sup></sup> + 1 ends in 26. <a title="Wikipedia article on base ten integer divisibility rules" href="http://en.wikipedia.org/wiki/Divisibility_rule">An integer is divisible by 4 if and only if its last two digits are divisible by 4</a>. Since 26 is not divisible by 4, neither is 5<sup>2<sup>f</sup></sup> + 1.</li>
</ul>
</li>
</ul>
<p>So the example expression 4(5<sup>1</sup> + 1)(5<sup>2</sup> + 1)(5<sup>4</sup> + 1)(5<sup>8</sup> + 1) has a factor of 2<sup>6</sup>: 2<sup>2</sup> times four factors of 2. </p>
<p>This generalizes to show that 5<sup>2<sup>n</sup></sup> &#8211; 1 is divisible by 2<sup>n+2</sup>. Recasting this from the perspective of the power of five to the modulus, let&#8217;s substitute m-2 for n. This gives the equivalent statement 5<sup>2<sup>m-2</sup></sup> &#8211; 1 is divisible by 2<sup>m</sup>. Just to be explicit, this implies that no 5<sup>2<sup>e</sup></sup>, e &lt; 2<sup>m-2</sup>, is divisible by 2<sup>m</sup>. So, the candidate power of two we were seeking is <strong>2<sup>m-2</sup>, the order of 5 mod 2<sup>m</sup></strong>.</p>
<h3>The Powers of Five Mod 2<sup>m</sup> Cycle Starting at 5<sup>0</sup></h3>
<p>Let the period p = 2<sup>m-2</sup>.  As we proved above, <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/06ab2fb22597579dee369e9c27c50e83.png' alt='\mbox{\footnotesize{\displaystyle{5^p \equiv 1 \pmod{2^m}}}}'/>. We also know, trivially, that <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/98c9e5a1783d8a98ca9f7e1214ed813a.png' alt='\mbox{\footnotesize{\displaystyle{5^0 \equiv 1 \pmod{2^m}}}}'/>. The difference between the exponents p and 0 is p, showing a full cycle occurs starting at 5<sup>0</sup>.</p>
<h2>Part 2: Period mod 10<sup>m</sup> is 2<sup>m-2</sup></h2>
<p>Part 2 shows, using the definition of <a title="Wikipedia article on modular arithmetic" href="http://en.wikipedia.org/wiki/Modular_arithmetic">modular arithmetic</a>, the <a title="Read Rick Regan's Article &ldquo;The Laws of Exponents&rdquo;" href="http://www.exploringbinary.com/the-laws-of-exponents/">laws of exponents</a>, and simple algebra, that the powers of five mod 10<sup>m</sup> have the same period as the powers of five mod 2<sup>m</sup>. It&#8217;s broken into two halves, showing that</p>
<ul>
<li>The period mod 2<sup>m</sup> is a cycle mod 10<sup>m</sup>.</li>
<li>The cycle mod 10<sup>m</sup> is the period mod 2<sup>m</sup>.</li>
</ul>
<p>The first half only shows that the period mod 2<sup>m</sup> is <em>a multiple</em> of the period mod 10<sup>m</sup>. The second half shows that the period mod 10<sup>m</sup> is in fact the same as the period mod 2<sup>m</sup>.</p>
<p>I&#8217;ll use the variable <em>p</em> for the period mod 2<sup>m</sup>, as above, to simplify the notation in the proof that follows.</p>
<h4>The period mod 2<sup>m</sup> is a cycle mod 10<sup>m</sup></h4>
<p>For i &ge; 0, what we&#8217;ve shown is that <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/6fd4af1d057b92ccd8f19b4aa441e8fb.png' alt='\mbox{\footnotesize{\displaystyle{5^{i+p} \equiv 5^i \pmod{2^m}}}}'/>. That is, powers of five with exponents a period apart are congruent mod 2<sup>m</sup>.</p>
<p>Congruence mod 2<sup>m</sup> means that 5<sup>i+p</sup> &#8211; 5<sup>i</sup> is a multiple of 2<sup>m</sup>; that is, 5<sup>i+p</sup> &#8211; 5<sup>i</sup> = n&middot;2<sup>m</sup>, for some nonnegative integer n.</p>
<p>Factoring out 5<sup>i</sup> we get 5<sup>i</sup>(5<sup>p</sup> &#8211; 1) = n&middot;2<sup>m</sup>. <strong>When i&ge;m, n is a multiple of 5<sup>m</sup></strong>, so n = n&#8217;&middot;5<sup>m</sup>.</p>
<p>Substituting n&#8217;&middot;5<sup>m</sup> for n we get 5<sup>i</sup>(5<sup>p</sup> &#8211; 1) = n&#8217;&middot;5<sup>m</sup>2<sup>m</sup> = n&#8217;&middot;10<sup>m</sup>.</p>
<p>Reversing the process above, we can show congruence mod 10<sup>m</sup>: </p>
<p>5<sup>i</sup>(5<sup>p</sup> &#8211; 1) = 5<sup>i+p</sup> &#8211; 5<sup>i</sup> = n&#8217;&middot;10<sup>m</sup>.</p>
<p>This shows that for i&ge;m, <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/4e39319c968be2bc9462ab6feae2ca25.png' alt='\mbox{\footnotesize{\displaystyle{5^{i+p} \equiv 5^i \pmod{10^m}}}}'/>, so p is a cycle mod 10<sup>m</sup>.</p>
<h4>The cycle mod 10<sup>m</sup> is the period mod 2<sup>m</sup></h4>
<p>We&#8217;ve shown that p is a cycle mod 10<sup>m</sup>, but not that p is the period mod 10<sup>m</sup>. In other words, it&#8217;s possible the period mod 10<sup>m</sup> is less than p &#8212; we have to show it isn&#8217;t.</p>
<p>For i &ge; m, we&#8217;ve shown that <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/4e39319c968be2bc9462ab6feae2ca25.png' alt='\mbox{\footnotesize{\displaystyle{5^{i+p} \equiv 5^i \pmod{10^m}}}}'/>. Using the argument above, congruence mod 10<sup>m</sup> means that:</p>
<p>5<sup>i+p</sup> &#8211; 5<sup>i</sup> = n&middot;10<sup>m</sup> = n&middot;5<sup>m</sup>2<sup>m</sup> = (n&middot;5<sup>m</sup>)2<sup>m</sup>.</p>
<p>This shows that for i&ge;m, <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-five-mod-powers-of-ten/6fd4af1d057b92ccd8f19b4aa441e8fb.png' alt='\mbox{\footnotesize{\displaystyle{5^{i+p} \equiv 5^i \pmod{2^m}}}}'/>, so p is the period mod 2<sup>m</sup> <em>and</em> mod 10<sup>m</sup>.</p>
<h2>Empirical Evidence</h2>
<p>This section is not part of the proof, but it shows some <a href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/" title="Read Rick Regan's Article &ldquo;Exploring Binary Numbers With PARI/GP Calculator&rdquo;">PARI/GP</a> calculations that support it.</p>
<p>Compute the order of 5 mod 2 through 5 mod 2<sup>16</sup> (you can see they&#8217;re powers of two):</p>
<pre>
? <strong>for(m=1,16,print(znorder(Mod(5,2^m))))</strong>
1
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
</pre>
<p class="break">Show the factors in 5<sup>16</sup> &#8211; 1:</p>
<pre>
? <strong>factor(5^16-1)</strong>
%1 =
<strong>[2 6]</strong>
[3 1]
[13 1]
[17 1]
[313 1]
[11489 1]

? <strong>factor(4*(5^1+1)*(5^2+1)*(5^4+1)*(5^8+1))</strong>
%2 =
<strong>[2 6]</strong>
[3 1]
[13 1]
[17 1]
[313 1]
[11489 1]

? <strong>factor((5^1+1))</strong>
%3 =
<strong>[2 1]</strong>
[3 1]

? <strong>factor((5^2+1))</strong>
%4 =
<strong>[2 1]</strong>
[13 1]

? <strong>factor((5^4+1))</strong>
%5 =
<strong>[2 1]</strong>
[313 1]

? <strong>factor((5^8+1))</strong>
%6 =
<strong>[2 1]</strong>
[17 1]
[11489 1]
</pre>
<p class="break">Show the factors of two in 5<sup>n</sup> &#8211; 1, n = 1 to 32 (you can see how the <a title="Read Rick Regan's Article &ldquo;Patterns in the Last Digits of the Positive Powers of Five&rdquo;" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/">nested cycles</a> correspond to the powers of two):</p>
<pre>
? <strong>for(i=1,32,print(&quot;5^&quot;,i,&quot;-1 has factor 2^&quot;,factor(5^i-1)[1,2]))</strong>

<strong>5^1-1 has factor 2^2</strong>
<strong>5^2-1 has factor 2^3</strong>
5^3-1 has factor 2^2
<strong>5^4-1 has factor 2^4</strong>
5^5-1 has factor 2^2
5^6-1 has factor 2^3
5^7-1 has factor 2^2
<strong>5^8-1 has factor 2^5</strong>
5^9-1 has factor 2^2
5^10-1 has factor 2^3
5^11-1 has factor 2^2
5^12-1 has factor 2^4
5^13-1 has factor 2^2
5^14-1 has factor 2^3
5^15-1 has factor 2^2
<strong>5^16-1 has factor 2^6</strong>
5^17-1 has factor 2^2
5^18-1 has factor 2^3
5^19-1 has factor 2^2
5^20-1 has factor 2^4
5^21-1 has factor 2^2
5^22-1 has factor 2^3
5^23-1 has factor 2^2
5^24-1 has factor 2^5
5^25-1 has factor 2^2
5^26-1 has factor 2^3
5^27-1 has factor 2^2
5^28-1 has factor 2^4
5^29-1 has factor 2^2
5^30-1 has factor 2^3
5^31-1 has factor 2^2
<strong>5^32-1 has factor 2^7</strong>
</pre>
<p>(The pattern of the powers of two is reminiscent of the <a title="Read Rick Regan's Article &ldquo;What a Binary Counter Looks and Sounds Like&rdquo;" href="http://www.exploringbinary.com/what-a-binary-counter-looks-and-sounds-like/">representation of powers of two in a binary counter</a>.)</p>
<h2>Discussion</h2>
<p>Part 2 of the proof is identical to part 2 of the proof in my article <a title="Read Rick Regan's Article &ldquo;Cycle Length of Powers of Two Mod Powers of Ten&rdquo;" href="http://www.exploringbinary.com/cycle-length-of-powers-of-two-mod-powers-of-ten/">&ldquo;Cycle Length of Powers of Two Mod Powers of Ten&rdquo;</a>, <strong>except that 5 and 2 are interchanged</strong>. Part 1 is quite different though. I could not use the same approach, since powers of two beyond four don&#8217;t have primitive roots.</p>
<p>Coming up with an alternate approach took some time. I had the elements of it early on: knowing that the order must be a power of two, knowing how to factor differences of squares, and knowing that each factor was even. But I was missing the piece that let me show each factor had <em>exactly</em> one factor of two &#8212; until I realized I could apply the divisibility by four test.</p>
<p>The binary structure of powers of a number computed <em>mod powers of two</em> make this approach possible (it should work for powers of any odd number, although it may be more difficult to show the factors of two).</p>
<h2>Summary</h2>
<p>To prove the period formula for the positive powers of five mod powers of ten, I first proved it for mod powers of two. I showed that the period must be a power of two, and derived an expression that showed <em>which</em> power of two. I then showed that the period mod powers of two and mod powers of ten must be the same, after a certain starting point.</p>
<p>I&#8217;ve previously shown a <a title="Read Rick Regan's Article &ldquo;Seeing Powers of Five in Powers of Two and Vice Versa&rdquo;" href="http://www.exploringbinary.com/seeing-powers-of-five-in-powers-of-two-and-vice-versa/">connection between the positive powers of five and negative powers of two</a>; now I&#8217;ve shown a connection between the positive powers of five and the <em>positive</em> powers of two.</p>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/cycle-length-of-powers-of-five-mod-powers-of-ten/">Cycle Length of Powers of Five Mod Powers of Ten</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/cycle-length-of-powers-of-five-mod-powers-of-ten/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Patterns in the Last Digits of the Positive Powers of Five</title>
		<link>http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/</link>
		<comments>http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 15:50:43 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Exponents]]></category>
		<category><![CDATA[Modular arithmetic]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=259</guid>
		<description><![CDATA[The positive powers of five &#8212; 5, 25, 125, 625, 3125, 15625, &#8230; &#8212; have a compact, repeating pattern in their ending m digits, in the powers of five from 5m on. For example: starting with 5, their last digit is always 5; starting with 25, their last two digits are always 25; starting with [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/">Patterns in the Last Digits of the Positive Powers of Five</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The positive powers of five &#8212; 5, 25, 125, 625, 3125, 15625, &#8230; &#8212; have a compact, repeating pattern in their ending <em>m</em> digits, in the powers of five from 5<sup>m</sup> on. For example: starting with 5, their last digit is always 5; starting with 25, their last two digits are always 25; starting with 125, their last three digits alternate between 125 and 625. These cycles come in lengths of powers of two.</p>
<div class="wp-caption aligncenter" style="width: 348px"><img src="http://www.exploringbinary.com/wp-content/uploads/PosPO5Cycles.jpg" alt="Cycles in the Ending Digits of the Powers of Five" width="338" height="375"/><p class="wp-caption-text">Cycles in the Ending Digits of the Powers of Five</p></div>
<p> I will show you why these cycles exist, how they are expressed mathematically, and how to visualize them.</p>
<p><span id="more-259"></span>(This article is the companion article to <a title="Read Rick Regan's Article &ldquo;Patterns in the Last Digits of the Positive Powers of Two&rdquo;" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-two/">&ldquo;Patterns in the Last Digits of the Positive Powers of Two&rdquo;</a>. It describes the digit patterns in the <em>negative</em> powers of two, indirectly, since <a title="Read Rick Regan's Article &ldquo;Seeing Powers of Five in Powers of Two and Vice Versa&rdquo;" href="http://www.exploringbinary.com/seeing-powers-of-five-in-powers-of-two-and-vice-versa/">positive powers of five look like negative powers of two</a>.)</p>
<h2>Cycles in the Last One to Four Digits</h2>
<p>You can use <a title="Wikipedia article on modular arithmetic" href="http://en.wikipedia.org/wiki/Modular_arithmetic">modular arithmetic</a> to show the repeating digit cycles of the positive powers of five. You can find the last m digits of a positive power by computing its <a title="Wolfram MathWorld definition of common residue" href="http://mathworld.wolfram.com/CommonResidue.html">common residue</a> mod 10<sup>m</sup>. You can find the last m digits of a <em>sequence</em> of powers by computing them incrementally, mod 10<sup>m</sup>. The cycle restarts when you get a result you&#8217;ve already seen.</p>
<h3>Last Digit</h3>
<p>Starting with 5, the last digit repeats in a cycle of period one: <strong>5</strong>. You show it with incremental calculations mod 10:</p>
<ol>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/37d926dfd0f791b1cff9bd68a62398cb.png' alt='\mbox{\footnotesize{\displaystyle{5^1 \equiv 5 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/435972351628ded738ddb0f6ac58f955.png' alt='\mbox{\footnotesize{\displaystyle{5^2 \equiv 5^1 \cdot 5 \equiv 5 \cdot 5 \equiv 25 \equiv \textbf{5} \pmod{10}}}}'/></li>
<li>&#8230;</li>
</ol>
<p>In other words, <strong>every positive power of five ends in 5</strong>.</p>
<h3>Last Two Digits</h3>
<p>Starting with 5<sup>2</sup>, the last two digits repeat in a cycle of period one: <strong>25</strong>. You show it with incremental calculations mod 10<sup>2</sup>:</p>
<ol>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/88e8c50bd6fc3a5719debd1c3ebe3a30.png' alt='\mbox{\footnotesize{\displaystyle{5^1 \equiv 5 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/a7f37d593e107718764f7619d0a6bb50.png' alt='\mbox{\footnotesize{\displaystyle{5^2 \equiv 5^1 \cdot 5 \equiv 5 \cdot 5 \equiv 25 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/263beba8816cb6c55d4942f49834a53b.png' alt='\mbox{\footnotesize{\displaystyle{5^3 \equiv 5^2 \cdot 5 \equiv 25 \cdot 5 \equiv 125 \equiv \textbf{25} \pmod{100}}}}'/></li>
<li>&#8230;</li>
</ol>
<h3>Last Three Digits</h3>
<p>Starting with 5<sup>3</sup>, the last three digits repeat in a cycle of period two: <strong>125, 625</strong>. You show it with incremental calculations mod 10<sup>3</sup>:</p>
<ol>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/c78c390b686a7bcbcb38ef4f0c395438.png' alt='\mbox{\footnotesize{\displaystyle{5^1 \equiv 5 \pmod{1000}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/d32574e530ca866d537b9d886bdb0696.png' alt='\mbox{\footnotesize{\displaystyle{5^2 \equiv 5^1 \cdot 5 \equiv 5 \cdot 5 \equiv 25 \pmod{1000}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/00f6f2bc5b9df285ea62a4402c81ea7d.png' alt='\mbox{\footnotesize{\displaystyle{5^3 \equiv 5^2 \cdot 5 \equiv 25 \cdot 5 \equiv 125 \pmod{1000}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/26b634db096bf579c6468e757f46cb43.png' alt='\mbox{\footnotesize{\displaystyle{5^4 \equiv 5^3 \cdot 5 \equiv 125 \cdot 5 \equiv 625 \pmod{1000}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/2939e6a26e782515e64ff8aeece414b6.png' alt='\mbox{\footnotesize{\displaystyle{5^5 \equiv 5^4 \cdot 5 \equiv 625 \cdot 5 \equiv 3125 \equiv \textbf{125} \pmod{1000}}}}'/></li>
<li>&#8230;</li>
</ol>
<h3>Last Four Digits</h3>
<p>Starting with 5<sup>4</sup>, the last four digits repeat in a cycle of period four: <strong>0625, 3125, 5625, 8125</strong>. You show it with incremental calculations mod 10<sup>4</sup>:</p>
<ol>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/7275dc358cd2863b38e8aff7cf045084.png' alt='\mbox{\footnotesize{\displaystyle{5^1 \equiv 5 \pmod{10000}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/5e145e0b129ffec86aad237518cb6ec3.png' alt='\mbox{\footnotesize{\displaystyle{5^2 \equiv 5^1 \cdot 5 \equiv 5 \cdot 5 \equiv 25 \pmod{10000}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/4118f15b6c04d14c210eb6be756bde2e.png' alt='\mbox{\footnotesize{\displaystyle{5^3 \equiv 5^2 \cdot 5 \equiv 25 \cdot 5 \equiv 125 \pmod{10000}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/c632200dfe951823b4a0f8b778beeabb.png' alt='\mbox{\footnotesize{\displaystyle{5^4 \equiv 5^3 \cdot 5 \equiv 125 \cdot 5 \equiv 625 \pmod{10000}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/48b7c42691d7617290d3788cb764c596.png' alt='\mbox{\footnotesize{\displaystyle{5^5 \equiv 5^4 \cdot 5 \equiv 625 \cdot 5 \equiv 3125 \pmod{10000}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/9b463197e075045f5501e213334d51cb.png' alt='\mbox{\footnotesize{\displaystyle{5^6 \equiv 5^5 \cdot 5 \equiv 3125 \cdot 5 \equiv 15625 \equiv 5625 \pmod{10000}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/3f98b87da4b99c0c464037ad6bd42fb5.png' alt='\mbox{\footnotesize{\displaystyle{5^7 \equiv 5^6 \cdot 5 \equiv 5625 \cdot 5 \equiv 28125 \equiv 8125 \pmod{10000}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-five/41386f7219e67c0a1227ffb9f3052859.png' alt='\mbox{\footnotesize{\displaystyle{5^8 \equiv 5^7 \cdot 5 \equiv 8125 \cdot 5 \equiv 40625 \equiv \textbf{625} \pmod{10000}}}}'/></li>
<li>&#8230;</li>
</ol>
<p>Whenever the residue is less than m digits, it is implicitly padded out with leading zeros. For example, the last 4 digits of 5<sup>8</sup> = 390625 are 0625.</p>
<h2>Cycles in the Last m Digits</h2>
<p>If you continue this process, you&#8217;ll see that the period doubles for each additional ending digit; I did the calculations through ten ending digits:</p>
<table class="center" border="1" summary="Cycle Length for Number of Ending Digits (1 to 10)">
<caption><strong>Cycle Length for Number of Ending Digits (1 to 10)</strong></caption>
<tbody>
<tr>
<th class="center">m</th>
<th class="center">Period</th>
<th class="center">Starts with</th>
</tr>
<tr>
<td class="center">1</td>
<td class="right">1</td>
<td class="right">5<sup>1</sup></td>
</tr>
<tr>
<td class="center">2</td>
<td class="right">1</td>
<td class="right">5<sup>2</sup></td>
</tr>
<tr>
<td class="center">3</td>
<td class="right">2</td>
<td class="right">5<sup>3</sup></td>
</tr>
<tr>
<td class="center">4</td>
<td class="right">4</td>
<td class="right">5<sup>4</sup></td>
</tr>
<tr>
<td class="center">5</td>
<td class="right">8</td>
<td class="right">5<sup>5</sup></td>
</tr>
<tr>
<td class="center">6</td>
<td class="right">16</td>
<td class="right">5<sup>6</sup></td>
</tr>
<tr>
<td class="center">7</td>
<td class="right">32</td>
<td class="right">5<sup>7</sup></td>
</tr>
<tr>
<td class="center">8</td>
<td class="right">64</td>
<td class="right">5<sup>8</sup></td>
</tr>
<tr>
<td class="center">9</td>
<td class="right">128</td>
<td class="right">5<sup>9</sup></td>
</tr>
<tr>
<td class="center">10</td>
<td class="right">256</td>
<td class="right">5<sup>10</sup></td>
</tr>
</tbody>
</table>
<p>This table implies that <strong>the ending m digits of the positive powers of five cycle with period 2<sup>m-2</sup>, m &ge; 2, starting at 5<sup>m</sup></strong>. (<a title="Read Rick Regan's Article &ldquo;Cycle Length of Powers of Five Mod Powers of Ten&rdquo;" href="http://www.exploringbinary.com/cycle-length-of-powers-of-five-mod-powers-of-ten/">The proof is here</a>.)</p>
<p>Powers of five with exponents that are congruent mod 2<sup>m-2</sup> are themselves congruent mod 10<sup>m</sup>. That is, 5<sup>i</sup> and 5<sup>i+(2<sup>m-2</sup>)&middot;k</sup>, i &ge; m, k &ge; 0, end with the same m digits.</p>
<h2>Visualizing the Nesting of Cycles</h2>
<p>The cycles in m digit, m-1 digit, m-2 digit, &#8230;, 1-digit endings can be viewed as nested, even though their starting points are staggered. You just have shift the starting points of the lesser digit cycles to make them coincide. For example, each copy of the length 4 cycle of four digit endings has within it two copies of the length 2 cycle of three digit endings; each copy of the length 2 cycle of three digit endings has within it 2 copies of the length 1 cycle of two digit endings.</p>
<p>This diagram shows the nesting by shading every other occurrence of a cycle (the millions place is fully shaded, because only one cycle of the last seven digits is shown):</p>
<div class="wp-caption aligncenter" style="width: 476px"><img src="http://www.exploringbinary.com/wp-content/uploads/PosPO5EndingDigits.jpg" alt="Nested 1-7 Digit Ending Patterns in Powers of 5 from 5^7to 5^38" width="466" height="740"/><p class="wp-caption-text">Nested 1-7 Digit Ending Patterns from 5<sup>7</sup> to 5<sup>38</sup></p></div>
<p>Not surprisingly, the nested powers of two in this pattern make it look similar to the pattern in <a title="Read Rick Regan's Article &ldquo;Visualizing Consecutive Binary Integers&rdquo;" href="http://www.exploringbinary.com/visualizing-consecutive-binary-integers/">consecutive binary integers</a>.</p>
<h3>Binary Tree</h3>
<p>Another way to show the nesting of powers of two is with a binary tree. Here is a tree showing the ending 1-5 digits:</p>
<div class="wp-caption aligncenter" style="width: 517px"><img src="http://www.exploringbinary.com/wp-content/uploads/PO5Tree.digits.png" alt="Binary Tree Showing Nested 1-5 Digit Ending Patterns (Digits)" width="507" height="301"/><p class="wp-caption-text">Binary Tree Showing Nested 1-5 Digit Ending Patterns (Digits)</p></div>
<p>Each level contains the ending digits for a given cycle, from the last digit (the root, or first level) to the eight 5 digit endings (the leaves, or fifth level). Starting with the second level, each m digit ending is the suffix of two m+1 digit endings. </p>
<p>Here&#8217;s the same tree, except labeled with the smallest power of five corresponding to the ending digits:</p>
<div class="wp-caption aligncenter" style="width: 494px"><img src="http://www.exploringbinary.com/wp-content/uploads/PO5Tree.powers.jpg" alt="Binary Tree Showing Nested 1-5 Digit Ending Patterns (Powers)" width="484" height="318"/><p class="wp-caption-text">Binary Tree Showing Nested 1-5 Digit Ending Patterns (Powers)</p></div>
<p>Each level from level 2 down includes the endings for 5<sup>m</sup> through 5<sup>(m+2<sup>m-2</sup>-1)</sup>.</p>
<p>Notice two interesting things that become apparent with the binary tree representations:</p>
<ul>
<li><strong>The starting digits of each pair of children, for m &ge; 3, differ by 5</strong>. For example, <span class="highlight_gray3">3</span>125 and <span class="highlight_gray3">8</span>125 on level 4 (digits 3 and 8).</li>
<li><strong>The exponents of each pair of children, for m &ge; 3, differ by 2<sup>m-3</sup></strong>. For example, 5<sup>5</sup> and 5<sup>7</sup> on level 4.</li>
</ul>
<p>(For more details, see my article <a href="http://www.exploringbinary.com/ending-digits-of-powers-of-five-form-a-binary-tree/" title="Read Rick Regan's Article &ldquo;Ending Digits of Powers of Five Form a Binary Tree&rdquo;">&ldquo;Ending Digits of Powers of Five Form a Binary Tree&rdquo;</a>.)</p>
<h2>Exploring Ending Digits with PARI/GP</h2>
<p>You can use <a href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/" title="Read Rick Regan's Article &ldquo;Exploring Binary Numbers With PARI/GP Calculator&rdquo;">PARI/GP</a> to explore the cycles in the ending digits; here are two examples:</p>
<ul>
<li><strong>Print the first 20 positive powers of five</strong>:
<pre>
? <strong>for(i=1,20,print(&quot;5^&quot;,i,&quot;: &quot;,5^i))</strong>
5^1: 5
5^2: 25
5^3: 125
5^4: 625
5^5: 3125
5^6: 15625
5^7: 78125
5^8: 390625
5^9: 1953125
5^10: 9765625
5^11: 48828125
5^12: 244140625
5^13: 1220703125
5^14: 6103515625
5^15: 30517578125
5^16: 152587890625
5^17: 762939453125
5^18: 3814697265625
5^19: 19073486328125
5^20: 95367431640625
</pre>
</li>
<li><strong>Show the cycle in the last m (in this case 5) digits</strong>:
<pre>
? <strong>m=5; for(i=1,2^(m-2)+m,print(&quot;5^&quot;,i,&quot; mod 10^&quot;,m&quot;: &quot;,5^i%10^m))</strong>
5^1 mod 10^5: 5
5^2 mod 10^5: 25
5^3 mod 10^5: 125
5^4 mod 10^5: 625
5^5 mod 10^5: <strong>3125</strong>
5^6 mod 10^5: <strong>15625</strong>
5^7 mod 10^5: <strong>78125</strong>
5^8 mod 10^5: <strong>90625</strong>
5^9 mod 10^5: <strong>53125</strong>
5^10 mod 10^5: <strong>65625</strong>
5^11 mod 10^5: <strong>28125</strong>
5^12 mod 10^5: <strong>40625</strong>
5^13 mod 10^5: 3125
</pre>
<p>(The leading 0 of 3125 is not printed.)</p>
</li>
</ul>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/">Patterns in the Last Digits of the Positive Powers of Five</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Seeing Powers of Five in Powers of Two and Vice Versa</title>
		<link>http://www.exploringbinary.com/seeing-powers-of-five-in-powers-of-two-and-vice-versa/</link>
		<comments>http://www.exploringbinary.com/seeing-powers-of-five-in-powers-of-two-and-vice-versa/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 18:26:14 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Algebra]]></category>
		<category><![CDATA[Decimals]]></category>
		<category><![CDATA[Exponents]]></category>
		<category><![CDATA[Fractions]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=257</guid>
		<description><![CDATA[The decimal representations of oppositely signed powers of two and powers of five look alike, as seen in these examples: 2-3 = 0.125 and 53 = 125; 5-5 = 0.00032 and 25 = 32. The significant digits in each pair of powers is the same, even though one is a fraction and one is an [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/seeing-powers-of-five-in-powers-of-two-and-vice-versa/">Seeing Powers of Five in Powers of Two and Vice Versa</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The decimal representations of oppositely signed powers of two and powers of five look alike, as seen in these examples: 2<sup>-3</sup> = 0.125 and 5<sup>3</sup> = 125; 5<sup>-5</sup> = 0.00032 and 2<sup>5</sup> = 32. The significant digits in each pair of powers is the same, even though one is a fraction and one is an integer. In other words, a negative power of one base looks like a positive power of the other.</p>
<div class="wp-caption aligncenter" style="width: 431px"><img src="http://www.exploringbinary.com/wp-content/uploads/PO2s PO5.jpg" alt="Powers of Two and Powers of Five that Look Alike" width="421" height="91"/><p class="wp-caption-text">Powers of Two and Powers of Five that Look Alike</p></div>
<p>This relationship is not coincidence; it&#8217;s a by-product of how fractions are represented as decimals. I&#8217;ll show you simple algebra that proves it, as well as algebra that proves similar properties &#8212; in products involving negative powers.</p>
<p><span id="more-257"></span></p>
<h2>Positive Powers of Five in Negative Powers of Two</h2>
<p>A <a title="Read Rick Regan's Article &ldquo;A Table of Negative Powers of Two&rdquo;" href="http://www.exploringbinary.com/a-table-of-negative-powers-of-two/">negative power of two</a> in decimal form looks like a positive power of five, except that it has a decimal point and possibly some leading zeros. Here are some examples, the first eight pairs of positive powers of five and negative powers of two:</p>
<table class="center" border="1">
<tbody>
<tr>
<th class="center">n</th>
<th class="center">5<sup>n</sup></th>
<th class="center">2<sup>-n</sup></th>
</tr>
<tr>
<td class="right small">1</td>
<td class="right small">5</td>
<td class="right small">0.5</td>
</tr>
<tr>
<td class="right small">2</td>
<td class="right small">25</td>
<td class="right small">0.25</td>
</tr>
<tr>
<td class="right small">3</td>
<td class="right small">125</td>
<td class="right small">0.125</td>
</tr>
<tr>
<td class="right small">4</td>
<td class="right small">625</td>
<td class="right small">0.0625</td>
</tr>
<tr>
<td class="right small">5</td>
<td class="right small">3125</td>
<td class="right small">0.03125</td>
</tr>
<tr>
<td class="right small">6</td>
<td class="right small">15625</td>
<td class="right small">0.015625</td>
</tr>
<tr>
<td class="right small">7</td>
<td class="right small">78125</td>
<td class="right small">0.0078125</td>
</tr>
<tr>
<td class="right small">8</td>
<td class="right small">390625</td>
<td class="right small">0.00390625</td>
</tr>
</tbody>
</table>
<p>The powers that are paired have exponents that are <em>additive inverses</em> of each other. It&#8217;s easy to show this relationship holds for all such pairs of powers. A negative power of two is a <a href="http://www.exploringbinary.com/the-powers-of-two/" title="Read Rick Regan's Article &ldquo;The Powers of Two&rdquo;">number of the form 2<sup>n</sup></a>, n and integer less than 0, or equivalently, a number of the form 2<sup>-n</sup>, n &gt; 0. By the <a title="Read Rick Regan's Article &ldquo;The Laws of Exponents&rdquo;" href="http://www.exploringbinary.com/the-laws-of-exponents/">laws of exponents</a>, 2<sup>-n</sup> = 1/2<sup>n</sup> = (1/2)<sup>n</sup> = (5/10)<sup>n</sup> = <strong>5<sup>n</sup>/10<sup>n</sup></strong>. Written as a decimal, 5<sup>n</sup>/10<sup>n</sup> looks like a positive power of five, except that it&#8217;s a fraction with n decimal places.</p>
<p>A different transformation gives another way to look at this: 2<sup>-n</sup> = 1/2<sup>n</sup> = (1/2)<sup>n</sup> =  (0.5)<sup>n</sup>. If you were to multiply this out by hand, you would ignore the decimal point, multiply all the factors of five, and then place the decimal point when you were done. You&#8217;d end up with a positive power of five, but preceded with a decimal point and zero or more leading 0s &#8212; to pad it out to n decimal places.</p>
<h2>Positive Powers of Two in Negative Powers of Five</h2>
<p>Not surprisingly, a similar relationship exists in reverse; that is, between the <a title="Read Rick Regan's Article &ldquo;A Table of Nonnegative Powers of Two&rdquo; (positive powers of two start at 2)" href="http://www.exploringbinary.com/a-table-of-nonnegative-powers-of-two/">positive powers of two</a> and the negative powers of five. This makes sense, given the role of the numbers two and five in the decimal system.</p>
<p>A negative power of five in decimal form looks like a positive power of two, except that it has a decimal point and possibly some leading zeros. Here are some examples, the first eight pairs of positive powers of two and negative powers of five:</p>
<table class="center" border="1">
<tbody>
<tr>
<th class="center">n</th>
<th class="center">2<sup>n</sup></th>
<th class="center">5<sup>-n</sup></th>
</tr>
<tr>
<td class="right small">1</td>
<td class="right small">2</td>
<td class="right small">0.2</td>
</tr>
<tr>
<td class="right small">2</td>
<td class="right small">4</td>
<td class="right small">0.04</td>
</tr>
<tr>
<td class="right small">3</td>
<td class="right small">8</td>
<td class="right small">0.008</td>
</tr>
<tr>
<td class="right small">4</td>
<td class="right small">16</td>
<td class="right small">0.0016</td>
</tr>
<tr>
<td class="right small">5</td>
<td class="right small">32</td>
<td class="right small">0.00032</td>
</tr>
<tr>
<td class="right small">6</td>
<td class="right small">64</td>
<td class="right small">0.000064</td>
</tr>
<tr>
<td class="right small">7</td>
<td class="right small">128</td>
<td class="right small">0.0000128</td>
</tr>
<tr>
<td class="right small">8</td>
<td class="right small">256</td>
<td class="right small">0.00000256</td>
</tr>
</tbody>
</table>
<p>Again, the powers that are paired have exponents that are additive inverses of each other. Using a similar transformation as above, we can show this relationship holds for all such pairs of powers: 5<sup>-n</sup> = 1/5<sup>n</sup> = (1/5)<sup>n</sup> = (2/10)<sup>n</sup> = <strong>2<sup>n</sup>/10<sup>n</sup></strong>. Written as a decimal, 2<sup>n</sup>/10<sup>n</sup> looks like a positive power of two, except that it&#8217;s a fraction with n decimal places.</p>
<p>There&#8217;s also an alternate way to view this: 5<sup>-n</sup> = 1/5<sup>n</sup> = (1/5)<sup>n</sup> =  (0.2)<sup>n</sup>. As above, think of it as multiplying the factors to get a power of two and then prefixing a decimal point and leading zeros.</p>
<h2>Products of Negative Powers of Two and Positive Powers of Five</h2>
<p>Because a negative power of two looks like a positive power of five, multiplying it by a positive power of five makes it look like yet another positive power of five. The resulting power of five has an exponent that is the sum of the absolute values of the exponents of the multiplied powers. For example: 2<sup>-3</sup>&middot;5<sup>4</sup> = 78.125, which looks like 5<sup>7</sup> = 78125; 2<sup>-7</sup>&middot;5<sup>3</sup> = 0.9765625, which looks like 5<sup>10</sup> = 9765625. </p>
<p>Algebraically, the multiplication is expressed as 2<sup>-t</sup>&middot;5<sup>f</sup>, with t, f &gt; 0. The result looks like 5<sup>(t+f)</sup>; here&#8217;s why: 2<sup>-t</sup> = 5<sup>t</sup>/10<sup>t</sup>, so 2<sup>-t</sup>&middot;5<sup>f</sup> = <strong>5<sup>(t+f)</sup>/10<sup>t</sup></strong>. This expression describes a positive power of five, only shifted right t decimal places.</p>
<p>You can think of these as looking like negative powers of two as well. The product 2<sup>-t</sup>&middot;5<sup>f</sup> can be written equivalently as 2<sup>-t</sup>&middot;5<sup>f</sup>&middot;(2<sup>-f</sup>&middot;2<sup>f</sup>) = <strong>2<sup>-(t+f)</sup>&middot;10<sup>f</sup></strong>, which is 2<sup>-(t+f)</sup> shifted left f decimal places.</p>
<h2>Products of Negative Powers of Five and Positive Powers of Two</h2>
<p>Similarly, the product of a negative power of five and a positive power of two looks like a positive power of two. For example, 5<sup>-3</sup>&middot;2<sup>3</sup> = 0.064, which looks like 2<sup>6</sup> = 64, and 5<sup>-4</sup>&middot;2<sup>12</sup> = 6.5536, which looks like 2<sup>16</sup> = 65536.</p>
<p>Algebraically, the multiplication is expressed as 5<sup>-f</sup>&middot;2<sup>t</sup>, with f, t &gt; 0. The result looks like 2<sup>(f+t)</sup>; here&#8217;s why: 5<sup>-f</sup> = 2<sup>f</sup>/10<sup>f</sup>, so 5<sup>-f</sup>&middot;2<sup>t</sup> = <strong>2<sup>(f+t)</sup>/10<sup>f</sup></strong>. This expression describes a positive power of two, only shifted right f decimal places.</p>
<p>You can think of these as looking like negative powers of five as well. The product 5<sup>-f</sup>&middot;2<sup>t</sup> can be written equivalently as 5<sup>-f</sup>&middot;2<sup>t</sup>&middot;(5<sup>-t</sup>&middot;5<sup>t</sup>) = <strong>5<sup>-(f+t)</sup>&middot;10<sup>t</sup></strong>, which is 5<sup>-(f+t)</sup> shifted left t decimal places.</p>
<h2>Products of Negative Powers of Two and Negative Powers of Five</h2>
<p>A negative power of two times a negative power of five results in a string of digits that looks like <em>either</em> a positive power of five or a positive power of two, depending on which exponent is smaller. For example, 2<sup>-4</sup>&middot;5<sup>-2</sup> = 0.0025, which looks like a positive power of five, and 2<sup>-2</sup>&middot;5<sup>-4</sup> = 0.0004, which looks like a positive power of two.</p>
<p>Algebraically, the multiplication is expressed as 2<sup>-t</sup>&middot;5<sup>-f</sup>, with t, f &gt; 0, and f  &ne; t. There are two cases:</p>
<ul>
<li><strong>f &lt; t</strong>: the result looks like 5<sup>(t-f)</sup>, with t decimal places. Here&#8217;s why:
<p>Recall from above that 2<sup>-t</sup> = 5<sup>t</sup>/10<sup>t</sup> and that 5<sup>-f</sup> = 2<sup>f</sup>/10<sup>f</sup>. This gives 2<sup>-t</sup>&middot;5<sup>-f</sup> = (5<sup>t</sup>/10<sup>t</sup>)(2<sup>f</sup>/10<sup>f</sup>) = (5<sup>t</sup>&middot;2<sup>f</sup>)/10<sup>(t+f)</sup>. Now factor out 10<sup>f</sup> from the numerator, which we can do since f &lt; t: (5<sup>t</sup>&middot;2<sup>f</sup>)/10<sup>(t+f)</sup> = (10<sup>f</sup>&middot;5<sup>(t-f)</sup>)/10<sup>(t+f)</sup> = <strong>5<sup>(t-f)</sup>/10<sup>t</sup></strong>.
</p>
</li>
<li><strong>t &lt; f</strong>: the result looks like 2<sup>(f-t)</sup>, with f decimal places. Here&#8217;s why:
<p>Starting from (5<sup>t</sup>&middot;2<sup>f</sup>)/10<sup>(t+f)</sup>, factor out 10<sup>t</sup> from the numerator, which we can do since t &lt; f: (5<sup>t</sup>&middot;2<sup>f</sup>)/10<sup>(t+f)</sup> = (10<sup>t</sup>&middot;2<sup>(f-t)</sup>)/10<sup>(t+f)</sup> = <strong>2<sup>(f-t)</sup>/10<sup>f</sup></strong>.
</p>
</li>
</ul>
<p>(If you allow f = t, the answer would be 2<sup>0</sup> = 5<sup>0</sup> = 1, a nonnegative power, with f = t decimal places.)
</p>
<h2>Discussion</h2>
<p>I came up with the algebra for the multiplication cases <em>after</em> I played around with some numbers in <a href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/" title="Read Rick Regan's Article &ldquo;Exploring Binary Numbers With PARI/GP Calculator&rdquo;">PARI/GP</a>. I noticed a pattern, and then sought to state it mathematically. </p>
<p>The patterns hold for quotients of powers as well, since divisions can be converted to multiplications by inverting exponents.</p>
<h3>Some Practical Uses</h3>
<p>If you know the positive powers of five, or if you learn them, you will recognize negative powers of two more readily &#8212; similarly for the positive powers of two and negative powers of five.</p>
<p>If you wanted to print a table of negative powers of two or negative powers of five using a computer program, you could do so easily, just by using integers: convert the positive powers to strings, and then prefix each with a decimal point and the appropriate number of leading zeros.</p>
<h2>References</h2>
<ul>
<li>learner.org article <a href="http://www.learner.org/courses/learningmath/number/session7/part_a/index.html" title="Read learner.org article discussing powers of two and powers of five">&ldquo;Fractions to Decimals&rdquo;</a>.</li>
</ul>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/seeing-powers-of-five-in-powers-of-two-and-vice-versa/">Seeing Powers of Five in Powers of Two and Vice Versa</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/seeing-powers-of-five-in-powers-of-two-and-vice-versa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cycle Length of Powers of Two Mod Powers of Ten</title>
		<link>http://www.exploringbinary.com/cycle-length-of-powers-of-two-mod-powers-of-ten/</link>
		<comments>http://www.exploringbinary.com/cycle-length-of-powers-of-two-mod-powers-of-ten/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 20:28:51 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Algebra]]></category>
		<category><![CDATA[Exponents]]></category>
		<category><![CDATA[Modular arithmetic]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=255</guid>
		<description><![CDATA[In my article &#8220;Patterns in the Last Digits of the Positive Powers of Two&#8221; I noted that the positive powers of two modulo 10m cycle with period 4&#183;5m-1, starting at 2m. For example, the powers of two mod 10 cycle with period four: 2, 4, 8, 6, 2, 4, 8, 6, &#8230; . In this [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/cycle-length-of-powers-of-two-mod-powers-of-ten/">Cycle Length of Powers of Two Mod Powers of Ten</a></p>
]]></description>
			<content:encoded><![CDATA[<p>In my article <a title="Read Rick Regan's Article &ldquo;Patterns in the Last Digits of the Positive Powers of Two&rdquo;" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-two/">&ldquo;Patterns in the Last Digits of the Positive Powers of Two&rdquo;</a> I noted that the positive powers of two modulo 10<sup>m</sup> cycle with period 4&middot;5<sup>m-1</sup>, starting at 2<sup>m</sup>. For example, the powers of two mod 10 cycle with period four: 2, 4, 8, 6, 2, 4, 8, 6, &#8230; . In this article, I&#8217;ll present my proof, which has two parts:</p>
<ul>
<li>Part 1 shows that the powers of two <strong>mod 5<sup>m</sup></strong> cycle with period 4&middot;5<sup>m-1</sup>, <strong>starting at 2<sup>0</sup></strong>.</li>
<li>Part 2 shows that the powers of two <strong>mod 10<sup>m</sup></strong> cycle with the same period as the powers of two mod 5<sup>m</sup>, <strong>starting at 2<sup>m</sup></strong>.</li>
</ul>
<p><span id="more-255"></span>To understand the proof, you&#8217;ll need to know some <a title="Wikipedia article on elementary number theory" href="http://en.wikipedia.org/wiki/Number_theory#Elementary_number_theory">elementary number theory</a>.</p>
<h2>Part 1: Period mod 5<sup>m</sup> is 4&middot;5<sup>m-1</sup></h2>
<p>The main goal of part 1 is to show that two is a <a title="Wikipedia article on primitive roots" href="http://en.wikipedia.org/wiki/Primitive_root_modulo_n">primitive root</a> mod powers of five, meaning that the <a title="Wikipedia article on multiplicative order" href="http://en.wikipedia.org/wiki/Multiplicative_order">order</a> of 2 mod 5<sup>m</sup> is the value of <a title="Wikipedia article on Euler's totient function" href="http://en.wikipedia.org/wiki/Euler%27s_totient_function">Euler&#8217;s phi function</a> for 5<sup>m</sup>. I break this into three steps, showing that</p>
<ul>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/1f355f9fb4d31e4e805b5bca35a0b22a.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (5^m)}}}'/> = 4&middot;5<sup>m-1</sup>, where <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/184ae9c731fbfbc2f1b43ca72d014388.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (n)}}}'/> is Euler&#8217;s phi function (also known as Euler&#8217;s totient function).</li>
<li>2 is a primitive root mod 5.</li>
<li>2 is a primitive root mod 5<sup>m</sup>.</li>
</ul>
<p>In addition, I show that the powers of two mod 5<sup>m</sup> cycle starting at 2<sup>0</sup>; this is important because it will show that the cycle mod 10<sup>m</sup> always starts after the cycle mod 5<sup>m</sup>.</p>
<h3><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/e49adba228c1034d35220364a784ab95.png' alt='\mbox{\footnotesize{\displaystyle{\bf{\varphi (5^m)}}}}'/> = 4&middot;5<sup>m-1</sup></h3>
<p><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/184ae9c731fbfbc2f1b43ca72d014388.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (n)}}}'/> is the number of positive integers less than or equal to n that are relatively prime to n. For a power of a prime number p, we can use <a title="Wikipedia article that shows the formula for Euler's Phi Function" href="http://en.wikipedia.org/wiki/Euler%27s_totient_function#Computing_Euler.27s_function">this formula</a> to compute it: <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/b00cb65570b30fb2762cf72221133b28.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (p^m) = (p \,$-$ 1) \cdot p^{m\,\textnormal{-}1}}}}'/>. For p=5, this gives <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/e49adba228c1034d35220364a784ab95.png' alt='\mbox{\footnotesize{\displaystyle{\bf{\varphi (5^m)}}}}'/> = 4&middot;5<sup>m-1</sup>.</p>
<h3>2 is a Primitive Root Mod 5</h3>
<p>To prove this, we just have to show that the order (also known as multiplicative order) of 2 mod 5 is equal to <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/dc27f8621c4cb0a44cee2326909bf835.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (5)}}}'/>.</p>
<p><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/dc27f8621c4cb0a44cee2326909bf835.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (5)}}}'/> = 4, by the formula above. The order of 2 mod 5 &#8212; the smallest exponent <em>a</em> such that <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/7a12e11a464d5c2f398cc07b12d8c068.png' alt='\mbox{\footnotesize{\displaystyle{2^a \equiv 1 \pmod{5}}}}'/>  &#8212; is four, as shown by the following sequence of four calculations:</p>
<ol>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/2c53ee0d065e7f59ccb35f4c12284f60.png' alt='\mbox{\footnotesize{\displaystyle{2^1 \equiv 2 \pmod{5}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/ed422d8632ac6032cca44f1af5abcede.png' alt='\mbox{\footnotesize{\displaystyle{2^2 \equiv 4 \pmod{5}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/6f970989bb37eb98565a64b18c96d2fe.png' alt='\mbox{\footnotesize{\displaystyle{2^3 \equiv 3 \pmod{5}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/31dfa53f1b0fe93191ff997b66013fb0.png' alt='\mbox{\footnotesize{\displaystyle{2^4 \equiv \textbf{1} \pmod{5}}}}'/></li>
</ol>
<p>Thus, 2 is a primitive root mod 5.</p>
<h3>2 is a Primitive Root Mod 5<sup>m</sup></h3>
<p>To show that 2 is a primitive root mod <em>all</em> positive powers of 5, we can use this result from <a title="Google Books Samples of &ldquo;A Course in Computational Algebraic Number Theory&rdquo;" href="http://books.google.com/books?id=hXGr-9l1DXcC&#038;pg=PP1&#038;dq=A+Course+in+Computational+Algebraic+Number+Theory&#038;ei=98TxSsRYjeSTBP7p6egL#v=snippet&#038;q=primitive&#038;f=false">page 26 of &ldquo;A Course in Computational Algebraic Number Theory&rdquo;</a> by Henri Cohen:</p>
<p><em>&ldquo;&#8230;to find a primitive root modulo p<sup>a</sup> for p an odd prime and a &ge; 2, proceed as follows: first compute g a primitive root modulo p &#8230;, then compute g<sub>1</sub> = g<sup>p-1</sup> mod p<sup>2</sup>. If g<sub>1</sub> &#8800; 1, g is a primitive root modulo p<sup>a</sup> for every a&#8230;&rdquo; .</em></p>
<p>In our case g = 2 and p = 5. We&#8217;ve already shown 2 to be a primitive root mod 5, so now all we need to show is that <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/543c2c73be226f796c06a88aea76f9d2.png' alt='\mbox{\footnotesize{\displaystyle{2^{5\,\textnormal{-}1} \not \equiv 1 \pmod{5^2}}}}'/>, which is trivial: <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/08661606ada56e75024a79726112d8a4.png' alt='\mbox{\footnotesize{\displaystyle{2^4 \equiv 16 \pmod{25}}}}'/>.</p>
<p>So, 2 is a primitive root mod 5<sup>m</sup>, which means that the order of 2 mod 5<sup>m</sup> is <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/1f355f9fb4d31e4e805b5bca35a0b22a.png' alt='\mbox{\footnotesize{\displaystyle{\varphi (5^m)}}}'/>. This proves that the powers of two mod 5<sup>m</sup> cycle with period 4&middot;5<sup>m-1</sup>.</p>
<h3>The Powers of Two Mod 5<sup>m</sup> Cycle Starting at 2<sup>0</sup></h3>
<p>Let the period p = 4&middot;5<sup>m-1</sup>. <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/251362c9141cdf5ea2259e3e88769feb.png' alt='\mbox{\footnotesize{\displaystyle{2^p \equiv 1 \pmod{5^m}}}}'/>, since 2 is a primitive root mod powers of 5 (<a title="Wikipedia article on Euler&rsquo;s theorem" href="http://en.wikipedia.org/wiki/Euler%27s_theorem">Euler&#8217;s theorem applies</a>). We also know, trivially, that <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/287636d2cc571728a931b6802618bdcb.png' alt='\mbox{\footnotesize{\displaystyle{2^0 \equiv 1 \pmod{5^m}}}}'/>. The difference between the exponents p and 0 is p, showing a full cycle occurs starting at 2<sup>0</sup>.</p>
<h2>Part 2: Period mod 10<sup>m</sup> is 4&middot;5<sup>m-1</sup></h2>
<p>Part 2 shows, using the definition of <a title="Wikipedia article on modular arithmetic" href="http://en.wikipedia.org/wiki/Modular_arithmetic">modular arithmetic</a>, the <a href="http://www.exploringbinary.com/composing-powers-of-two-using-the-laws-of-exponents/" title="Read Rick Regan's Article &ldquo;Composing Powers of Two Using The Laws of Exponents&rdquo;">laws of exponents</a>, and simple algebra, that the powers of two mod 10<sup>m</sup> have the same period as the powers of two mod 5<sup>m</sup>. It&#8217;s broken into two halves, showing that</p>
<ul>
<li>The period mod 5<sup>m</sup> is a cycle mod 10<sup>m</sup>.</li>
<li>The cycle mod 10<sup>m</sup> is the period mod 5<sup>m</sup>.</li>
</ul>
<p>The first half only shows that the period mod 5<sup>m</sup> is <em>a multiple</em> of the period mod 10<sup>m</sup>. The second half shows that the period mod 10<sup>m</sup> is in fact the same as the period mod 5<sup>m</sup>.</p>
<p>I&#8217;ll use the variable <em>p</em> for the period mod 5<sup>m</sup>, as above, to simplify the notation in the proof that follows.</p>
<h4>The period mod 5<sup>m</sup> is a cycle mod 10<sup>m</sup></h4>
<p>For i &ge; 0, what we&#8217;ve shown is that <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/e77db816df140e7c827d0a78f1a1fb50.png' alt='\mbox{\footnotesize{\displaystyle{2^{i+p} \equiv 2^i \pmod{5^m}}}}'/>. That is, powers of two with exponents a period apart are congruent mod 5<sup>m</sup>.</p>
<p>Congruence mod 5<sup>m</sup> means that 2<sup>i+p</sup> &#8211; 2<sup>i</sup> is a multiple of 5<sup>m</sup>; that is, 2<sup>i+p</sup> &#8211; 2<sup>i</sup> = n&middot;5<sup>m</sup>, for some nonnegative integer n.</p>
<p>Factoring out 2<sup>i</sup> we get 2<sup>i</sup>(2<sup>p</sup> &#8211; 1) = n&middot;5<sup>m</sup>. <strong>When i&ge;m, n is a multiple of 2<sup>m</sup></strong>, so n = n&#8217;&middot;2<sup>m</sup>.</p>
<p>Substituting n&#8217;&middot;2<sup>m</sup> for n we get 2<sup>i</sup>(2<sup>p</sup> &#8211; 1) = n&#8217;&middot;2<sup>m</sup>5<sup>m</sup> = n&#8217;&middot;10<sup>m</sup>.</p>
<p>Reversing the process above, we can show congruence mod 10<sup>m</sup>: </p>
<p>2<sup>i</sup>(2<sup>p</sup> &#8211; 1) = 2<sup>i+p</sup> &#8211; 2<sup>i</sup> = n&#8217;&middot;10<sup>m</sup>.</p>
<p>This shows that for i&ge;m, <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/e2507013f02cbab05d150cbe86fecb65.png' alt='\mbox{\footnotesize{\displaystyle{2^{i+p} \equiv 2^i \pmod{10^m}}}}'/>, so p is a cycle mod 10<sup>m</sup>.</p>
<h4>The cycle mod 10<sup>m</sup> is the period mod 5<sup>m</sup></h4>
<p>We&#8217;ve shown that p is a cycle mod 10<sup>m</sup>, but not that p is the period mod 10<sup>m</sup>. In other words, it&#8217;s possible the period mod 10<sup>m</sup> is less than p &#8212; we have to show it isn&#8217;t.</p>
<p>For i &ge; m, we&#8217;ve shown that <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/e2507013f02cbab05d150cbe86fecb65.png' alt='\mbox{\footnotesize{\displaystyle{2^{i+p} \equiv 2^i \pmod{10^m}}}}'/>. Using the argument above, congruence mod 10<sup>m</sup> means that:</p>
<p>2<sup>i+p</sup> &#8211; 2<sup>i</sup> = n&middot;10<sup>m</sup> = n&middot;2<sup>m</sup>5<sup>m</sup> = (n&middot;2<sup>m</sup>)5<sup>m</sup>.</p>
<p>This shows that for i&ge;m, <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/cycle-length-of-powers-of-two-mod-powers-of-ten/e77db816df140e7c827d0a78f1a1fb50.png' alt='\mbox{\footnotesize{\displaystyle{2^{i+p} \equiv 2^i \pmod{5^m}}}}'/>, so p is the period mod 5<sup>m</sup> <em>and</em> mod 10<sup>m</sup>.</p>
<h2>Empirical Evidence that 2 is a Primitive Root mod 5<sup>m</sup></h2>
<p>This section is not part of the proof, but it shows some <a href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/" title="Read Rick Regan's Article &ldquo;Exploring Binary Numbers With PARI/GP Calculator&rdquo;">PARI/GP</a> calculations that support it.</p>
<p>These two commands show indirectly that 2 is a primitive root mod 5 through mod 5<sup>20</sup>, by showing that the order equals Euler&#8217;s phi function:</p>
<pre>
? <strong>for(m=1,20,print(eulerphi(5^m)))</strong>
4
20
100
500
2500
12500
62500
312500
1562500
7812500
39062500
195312500
976562500
4882812500
24414062500
122070312500
610351562500
3051757812500
15258789062500
76293945312500

? <strong>for(m=1,20,print(znorder(Mod(2,5^m))))</strong>
4
20
100
500
2500
12500
62500
312500
1562500
7812500
39062500
195312500
976562500
4882812500
24414062500
122070312500
610351562500
3051757812500
15258789062500
76293945312500
</pre>
<p class="break">This command shows directly that 2 is a primitive root mod powers of 5, using PARI/GP&#8217;s <em>znprimroot() </em>function (znprimroot only returns the lowest primitive root, which luckily for us is 2):</p>
<pre>
? <strong>for(m=1,20,print(znprimroot(5^m)))</strong>
Mod(2, 5)
Mod(2, 25)
Mod(2, 125)
Mod(2, 625)
Mod(2, 3125)
Mod(2, 15625)
Mod(2, 78125)
Mod(2, 390625)
Mod(2, 1953125)
Mod(2, 9765625)
Mod(2, 48828125)
Mod(2, 244140625)
Mod(2, 1220703125)
Mod(2, 6103515625)
Mod(2, 30517578125)
Mod(2, 152587890625)
Mod(2, 762939453125)
Mod(2, 3814697265625)
Mod(2, 19073486328125)
Mod(2, 95367431640625)
</pre>
<h2>Summary</h2>
<p>To prove the period formula for the positive powers of two mod powers of ten, I first proved it for mod powers of five. I showed that two is a primitive root mod powers of five, meaning that the period formula is Euler&#8217;s phi function for the powers of five. I then showed that the period mod powers of five and mod powers of ten must be the same, after a certain starting point.</p>
<h2>References</h2>
<p>These are the main influences behind my proof:</p>
<ul>
<li><a title="Google Books Samples of &ldquo;Challenging Mathematical Problems with Elementary Solutions, Volume 1&rdquo;" href="http://books.google.com/books?id=aVLLYiu8hs0C&#038;dq=Challenging+mathematical+problems+with+elementary+solutions,+Volume+1&#038;printsec=frontcover&#038;source=bl&#038;ots=30xgjayaSv&#038;sig=q8qvXsBFG9zogCZWJ-S4YCxHXl0&#038;hl=en&#038;ei=Wk7oSonjJNXtlAeqxNSMCA&#038;sa=X&#038;oi=book_result&#038;ct=result&#038;resnum=3&#038;ved=0CBMQ6AEwAg#v=onepage&#038;q=&#038;f=false">Challenging Mathematical Problems with Elementary Solutions, Volume 1</a>. Page 198: &ldquo;It can be proved that the last k digits of the number 2<sup>n</sup> are repeated in groups of 4&middot;5<sup>k-1</sup>, starting with the number 2<sup>k</sup>.&rdquo;</li>
<li><a title="Google Books Samples of &ldquo;The USSR Olympiad Problem Book; Selected Problems and Theorems of Elementary Mathematics&rdquo;" href="http://books.google.com/books?id=ONCQUUWjUc8C&#038;dq=The+USSR+olympiad+problem+book;+selected+problems+and+theorems+of+elementary+mathematics&#038;printsec=frontcover&#038;source=bn&#038;hl=en&#038;ei=hVDoSqqMLdCTlAevlrz8Bw&#038;sa=X&#038;oi=book_result&#038;ct=result&#038;resnum=4&#038;ved=0CA8Q6AEwAw#v=onepage&#038;q=&#038;f=false">The USSR Olympiad Problem Book; Selected Problems and Theorems of Elementary Mathematics</a>. Page 57, problem 243, and its answer, on page 354, discuss the case for powers of two mod 10<sup>10</sup>.</li>
<li><a title="Question I asked at physicsforums.com" href="http://www.physicsforums.com/showthread.php?p=2400449#post2400449">Question I asked at physicsforums.com</a>. User  <em>hamster143</em>&#8216;s proof that the period for powers of five and ten are equal.</li>
<li><a title="Entry by user shmoe at physicsforums.com" href="http://www.physicsforums.com/archive/index.php/t-76662.html">Discussion at physicsforums.com</a>. User <em>shmoe</em>&#8216;s comment: &ldquo;a power of 2&#8242;s congruence class mod 10 is completely determined by its congruence class mod 5&rdquo;.</li>
<li><a title="Hakmem Item 57" href="http://inwap.com/pdp10/hbaker/hakmem/number.html">Hakmem Item 57</a>. Two comments by <em>Schroeppel</em>:
<ul>
<li>&ldquo;After the nth, they are all multiples of 2<sup>n</sup>.&rdquo;</li>
<li>&ldquo;They get into a loop of length 4&middot;5<sup>m-1</sup>. (Because 2 is a primitive root of powers of 5.)&rdquo;</li>
</ul>
</li>
<li><a title="Question I asked at mathoverflow.net" href="http://mathoverflow.net/questions/919/cycle-length-of-the-positive-powers-of-two-mod-powers-of-ten">Question I asked at mathoverflow.net</a>.</li>
</ul>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/cycle-length-of-powers-of-two-mod-powers-of-ten/">Cycle Length of Powers of Two Mod Powers of Ten</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/cycle-length-of-powers-of-two-mod-powers-of-ten/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Find the Last Digits of a Positive Power of Two</title>
		<link>http://www.exploringbinary.com/how-to-find-the-last-digits-of-a-positive-power-of-two/</link>
		<comments>http://www.exploringbinary.com/how-to-find-the-last-digits-of-a-positive-power-of-two/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 22:18:42 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Exponents]]></category>
		<category><![CDATA[Modular arithmetic]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=251</guid>
		<description><![CDATA[A common exercise in number theory is to find the last digits of a large power, like 22009, without using a computer. 22009 is a 605-digit number, so evaluating it by hand is out of the question. So how do you find its last digits &#8212; efficiently? Modular arithmetic, and in particular, modular exponentiation, comes [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/how-to-find-the-last-digits-of-a-positive-power-of-two/">How to Find the Last Digits of a Positive Power of Two</a></p>
]]></description>
			<content:encoded><![CDATA[<p>A common exercise in number theory is to find the last digits of a large power, like 2<sup>2009</sup>, without using a computer. 2<sup>2009</sup> is a 605-digit number, so evaluating it by hand is out of the question. So how do you find its last digits &#8212; efficiently?</p>
<p>Modular arithmetic, and in particular, <a title="Wikipedia article on modular exponentiation" href="http://en.wikipedia.org/wiki/Modular_exponentiation">modular exponentiation</a>, comes to the rescue. It provides an efficient way to find the last m digits of a power, by hand, with perhaps only a little help from a pocket calculator. All you need to do is compute the power incrementally, modulo 10<sup>m</sup>.</p>
<p>In this article, I will discuss three methods &#8212; all based on modular exponentiation and the laws of exponents &#8212; for finding the ending digits of a positive <a href="http://www.exploringbinary.com/the-powers-of-two/" title="Read Rick Regan's Article &ldquo;The Powers of Two&rdquo;">power of two</a>. The techniques I use are easily adapted to powers of any number.</p>
<p><span id="more-251"></span></p>
<h2>1. Ad Hoc Exponentiation</h2>
<p>In this method, you reduce a power of two modulo 10<sup>m</sup> repeatedly until you get a congruent power, or product of powers, for which the end digits are known &#8212; or easily computed. You use your knowledge of smaller powers of two, in conjunction with the <a href="http://www.exploringbinary.com/composing-powers-of-two-using-the-laws-of-exponents/" title="Read Rick Regan's Article &ldquo;Composing Powers of Two Using The Laws of Exponents&rdquo;">power of a power and product of powers rules</a>, to set up easier sub problems to solve.</p>
<p>You start by dividing the exponent of 2<sup>n</sup> by the exponent of a known, smaller power of two, 2<sup>a</sup>, getting a quotient q and a remainder r. You then rewrite 2<sup>n</sup> as (2<sup>a</sup>)<sup>q</sup> &middot; 2<sup>r</sup>.</p>
<h3>Finding the Last Digit</h3>
<p>I&#8217;ve categorized two sub methods of the ad hoc method that make it more systematic when dealing specifically with powers of two. I call them the <strong>powers of two method</strong> and the <strong>powers of six method</strong>.</p>
<h4>Powers of Two Method</h4>
<p>In the powers of two method, you reduce a power of two by using a power of two ending in 2. This reduces the problem at each stage to a smaller power of two, giving the method a recursive feel. The intermediate powers of two are in effect nested.</p>
<p>For example, let&#8217;s find the last digit of 2<sup>2009</sup>, using 2<sup>5</sup> (32) to reduce the problem at each step:</p>
<ul>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/e42849b13d849332c2156d11077feb7b.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv {\left(2^{5}\right)}^{401} \cdot2^4 \equiv 2^{401} \cdot2^4 \equiv 2^{405} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/cd665748bbd452052cf8832d883acaf0.png' alt='\mbox{\footnotesize{\displaystyle{2^{405} \equiv {\left(2^{5}\right)}^{81} \equiv 2^{81} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/99af5e6a6951ce1b5369876e32506282.png' alt='\mbox{\footnotesize{\displaystyle{2^{81} \equiv {\left(2^{5}\right)}^{16} \cdot2^1 \equiv 2^{16} \cdot2^1 \equiv 2^{17} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/34e90be503c8f48ed2c24401aaa22ad3.png' alt='\mbox{\footnotesize{\displaystyle{2^{17} \equiv {\left(2^{5}\right)}^{3} \cdot2^2 \equiv 2^{3} \cdot2^2 \equiv 2^{5} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/5140d00773d2b2e3440bf09fa994ad98.png' alt='\mbox{\footnotesize{\displaystyle{2^5 \equiv \textbf{2} \pmod{10}}}}'/></li>
</ul>
<p>So <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/bf936a4fd8645866885de12b816eda67.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv 2 \pmod{10}}}}'/>, showing that 2<sup>2009</sup> ends in 2.</p>
<p>The intermediate results &#8212; 2<sup>405</sup>, 2<sup>81</sup>, 2<sup>17</sup>, and 2<sup>5</sup> &#8212; are all congruent, ending in 2. If you recognize this along the way, you can stop. For example, if you happen to know that 2<sup>17</sup> is 131,072, you can stop after the third step.</p>
<p>Any power of two ending in 2 works. Here&#8217;s how the process goes when using 2<sup>9</sup> (512):</p>
<ul>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/32e1479578f38a7e9a2a58cac6c53b1e.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv {\left(2^{9}\right)}^{223} \cdot2^2 \equiv 2^{223} \cdot2^2 \equiv 2^{225} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/72d2dc31bc73ce3fea54b538471f0038.png' alt='\mbox{\footnotesize{\displaystyle{2^{225} \equiv {\left(2^{9}\right)}^{25} \equiv 2^{25} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/d5340880581a47493757009457a60863.png' alt='\mbox{\footnotesize{\displaystyle{2^{25} \equiv {\left(2^{9}\right)}^{2} \cdot2^7 \equiv 2^{2} \cdot2^7 \equiv 2^{9} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/e63ac5aa5f7608f4507823ccc60cb261.png' alt='\mbox{\footnotesize{\displaystyle{2^9 \equiv \textbf{2} \pmod{10}}}}'/></li>
</ul>
<p>Using 2<sup>9</sup>, there is one less step, but the arithmetic is slightly harder (division by 9 instead of division by 5).</p>
<h4>Powers of Six Method</h4>
<p>In the powers of six method, you reduce a power of two using a power of two that ends in 6. This introduces powers of six, which have to be handled separately and combined with the &#8220;remainder&#8221; powers of two. For example, let&#8217;s do our example with 2<sup>4</sup> = 16. The first step would give:</p>
<p><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/0bdf4b3cc4a5fddf63dece527286f47c.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv {\left(2^{4}\right)}^{502} \cdot2^1 \equiv 6^{502} \cdot2^1 \pmod{10}}}}'/></p>
<p>But wait! All powers of six end in 6 (6 times 6 mod 10 is 6, and around it goes&#8230;), so we just turned this into a very simple problem: <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/42df08d0e544730aa67df89cdba47e89.png' alt='\mbox{\footnotesize{\displaystyle{6 \cdot 2 \equiv 2 \pmod{10}}}}'/>.</p>
<p>So, while it doesn&#8217;t have the elegance of the powers of two method, the powers of six method is simpler.</p>
<h3>Finding the Last Two Digits</h3>
<p>The powers of six method does not apply to mod 100, but the powers of two method does &#8212; indirectly. Although there is no power of two that ends in 02, we can use any two-digit ending that is a power of two; we just convert it to 2<sup>y</sup> using the laws of exponents.</p>
<p>Let&#8217;s go back to our example, 2<sup>2009</sup>. Consulting a <a title="Read Rick Regan's Article “A Table of Nonnegative Powers of Two” (positive powers of two start at 2)" href="http://www.exploringbinary.com/a-table-of-nonnegative-powers-of-two/">table of positive powers of two</a>, find a power of two that ends in 04; for example, 2<sup>22</sup> (4,194,304). Let&#8217;s use this to reduce our problem at each step:</p>
<ul>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/eb9daa5d3ef7d1902a1ce8c2af46a8dc.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv {\left(2^{22}\right)}^{91} \cdot 2^7 \equiv 4^{91} \cdot 2^7 \equiv 2^{182} \cdot 2^7 \equiv 2^{189} \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/e046368e93a9a52e8b3e5ff88eba12d6.png' alt='\mbox{\footnotesize{\displaystyle{2^{189} \equiv {\left(2^{22}\right)}^{8} \cdot 2^{13} \equiv 4^8 \cdot 2^{13} \equiv 2^{16} \cdot 2^{13} \equiv 2^{29} \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/8d7f7aee2b901674e746304d6012ee6c.png' alt='\mbox{\footnotesize{\displaystyle{2^{29} \equiv 2^{22} \cdot 2^7 \equiv 4 \cdot 2^7 \equiv 2^2 \cdot 2^7 \equiv 2^9 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/eff80d9d679ce5ed3d3e340ca5618613.png' alt='\mbox{\footnotesize{\displaystyle{2^9 \equiv \textbf{12} \pmod{100}}}}'/></li>
</ul>
<h3>Finding the Last m Digits</h3>
<p>For the last m digits, find an m-digit power of two greater than or equal to 2<sup>m</sup> and convert it to 2<sup>y</sup> as above. Of course, the remainders will become larger and larger as the modulus increases.</p>
<h2>2. Successive Squaring</h2>
<p>The method of <a title="Wolfram MathWorld definition of the successive square method of modular exponentiation" href="http://mathworld.wolfram.com/SuccessiveSquareMethod.html">successive squaring</a>, also called repeated squaring or <a title="Dr. Math article on binary exponentiation" href="http://mathforum.org/library/drmath/view/55603.html"> binary exponentiation</a>, is a very systematic way to do modular exponentiation. It&#8217;s a generic four step process applicable to any base and modulus, but here&#8217;s how to use it to compute 2<sup>n</sup> mod 10<sup>m</sup> specifically:</p>
<ol>
<li>Rewrite 2<sup>n</sup> so that n is a sum of powers of two (essentially, convert n to binary).</li>
<li>Rewrite 2<sup>n</sup> using the product of powers rule.</li>
<li>Create a list of powers 2<sup>2<sup>i</sup></sup> mod 10<sup>m</sup>, by repeatedly squaring the prior result.</li>
<li>Combine, with multiplication mod 10<sup>m</sup>, the powers in the list that make up 2<sup>n</sup>.</li>
</ol>
<p>This process is independent of the number of ending digits m, although you have to deal with bigger and bigger numbers as m increases.</p>
<h3>Example: Find the Last Digit of 2<sup>2009</sup></h3>
<p>Let&#8217;s use this method to find the last digit of 2<sup>2009</sup>:</p>
<ol>
<li>2<sup>2009</sup> = 2<sup>1024 + 512 + 256 + 128 + 64 + 16 + 8 + 1</sup></li>
<li>2<sup>2009</sup> = 2<sup>1024</sup> &middot; 2<sup>512</sup> &middot; 2<sup>256</sup> &middot; 2<sup>128</sup> &middot; 2<sup>64</sup> &middot; 2<sup>16</sup> &middot; 2<sup>8</sup> &middot; 2<sup>1</sup></li>
<li>Create a list of powers of two raised to powers of two, mod 10:
<ul>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/4bfe3dc9b57002742d48f59d2e2b570d.png' alt='\mbox{\footnotesize{\displaystyle{2^1 \equiv 2 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/7f1b2bbdb43d068709e2e274b536289c.png' alt='\mbox{\footnotesize{\displaystyle{2^2 \equiv 4 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/2608c7f833e609e96854d2e0c90ef2fe.png' alt='\mbox{\footnotesize{\displaystyle{2^4 \equiv 4^2 \equiv 6 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/edda63a642e32ce7d50299930ef4383d.png' alt='\mbox{\footnotesize{\displaystyle{2^8 \equiv 6^2 \equiv 6 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/1b5ccfb9100c30eb1a4d102b574bafaf.png' alt='\mbox{\footnotesize{\displaystyle{2^{16} \equiv 6^2 \equiv 6 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/6a26d8cf64dc9387cfd433adb434382f.png' alt='\mbox{\footnotesize{\displaystyle{2^{32} \equiv 6^2 \equiv 6 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/e07800aa82ea0d79df3cc29b1a4480c8.png' alt='\mbox{\footnotesize{\displaystyle{2^{64} \equiv 6^2 \equiv 6 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/049b7ebb30eff33d3dbde0b8508da485.png' alt='\mbox{\footnotesize{\displaystyle{2^{128} \equiv 6^2 \equiv 6 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/8d6054853d38f1bde584b216341c8271.png' alt='\mbox{\footnotesize{\displaystyle{2^{256} \equiv 6^2 \equiv 6 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/fd5cb704944d9c8cf5006b7645b78458.png' alt='\mbox{\footnotesize{\displaystyle{2^{512} \equiv 6^2 \equiv 6 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/75e90be6e7fc2c429ee00a0dc7feb1c0.png' alt='\mbox{\footnotesize{\displaystyle{2^{1024} \equiv 6^2 \equiv 6 \pmod{10}}}}'/></li>
</ul>
<p>(I wrote out the whole list for completeness, but it was unnecessary to go beyond 2<sup>4</sup>. Again, that&#8217;s because all powers of six end in 6.)</p>
</li>
<li>Combine the required powers:
<ul>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/c9574ea48db74e138bdaaba8e2f9d053.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv 2^{1024} \cdot 2^{512} \cdot 2^{256} \cdot 2^{128} \cdot 2^{64} \cdot 2^{16} \cdot 2^8 \cdot 2^1 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/733af9f3886437ed42d2f6277eb1f80a.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv 6 \cdot 6 \cdot 6 \cdot 6 \cdot 6 \cdot 6 \cdot 6 \cdot 2 \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/3ca9e3bc4b1bc483ab61b08456f90536.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv 6^7 \cdot 2  \equiv 6 \cdot 2 \equiv \textbf{2} \pmod{10}}}}'/></li>
</ul>
</li>
</ol>
<h3>Example: Find the Last Two Digits of 2<sup>2009</sup></h3>
<p>Let&#8217;s use this method to find the last <em>two</em> digits of 2<sup>2009</sup>:</p>
<ol>
<li>2<sup>2009</sup> = 2<sup>1024 + 512 + 256 + 128 + 64 + 16 + 8 + 1</sup></li>
<li>2<sup>2009</sup> = 2<sup>1024</sup> &middot; 2<sup>512</sup> &middot; 2<sup>256</sup> &middot; 2<sup>128</sup> &middot; 2<sup>64</sup> &middot; 2<sup>16</sup> &middot; 2<sup>8</sup> &middot; 2<sup>1</sup></li>
<li>Create a list of powers of two raised to powers of two, mod 100:
<ul>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/69d51bbbdf163b3f65f4d1afa727c4be.png' alt='\mbox{\footnotesize{\displaystyle{2^1 \equiv 2 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/e6b55a4314e33bd4c349c5753c51e204.png' alt='\mbox{\footnotesize{\displaystyle{2^2 \equiv 4 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/5930d220417bdcf68acb0e92fff03107.png' alt='\mbox{\footnotesize{\displaystyle{2^4 \equiv 16 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/0b36d06edbad680725a29159769b745b.png' alt='\mbox{\footnotesize{\displaystyle{2^8 \equiv 16^2 \equiv 56 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/65dd44cc2f10b4ea770896b87a32633c.png' alt='\mbox{\footnotesize{\displaystyle{2^{16} \equiv 56^2 \equiv 36 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/5dd303fb234a7ccff42acd5df4fe8118.png' alt='\mbox{\footnotesize{\displaystyle{2^{32} \equiv 36^2 \equiv 96 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/0fdc13db8dedb8098d1958a02bfe0e85.png' alt='\mbox{\footnotesize{\displaystyle{2^{64} \equiv 96^2 \equiv 16 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/36f9b4977519ef2195d9d75ad82c78f4.png' alt='\mbox{\footnotesize{\displaystyle{2^{128} \equiv 16^2 \equiv 56 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/42b1cb87df181d99acef1aaa65c11dd2.png' alt='\mbox{\footnotesize{\displaystyle{2^{256} \equiv 56^2 \equiv 36 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/ea7cca82f2f249cd08016d30cdf02e2b.png' alt='\mbox{\footnotesize{\displaystyle{2^{512} \equiv 36^2 \equiv 96 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/990db93a0d2d770b79f57f5fde54b452.png' alt='\mbox{\footnotesize{\displaystyle{2^{1024} \equiv 96^2 \equiv 16 \pmod{100}}}}'/></li>
</ul>
<p>(Notice that the powers in this list cycle after a point, so it is not necessary to compute them all.)</p>
</li>
<li>Combine the required powers:
<ul>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/63a842e2b2a551ab946138814dd80ecd.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv 2^{1024} \cdot 2^{512} \cdot 2^{256} \cdot 2^{128} \cdot 2^{64} \cdot 2^{16} \cdot 2^8 \cdot 2^1 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/9874a0b684b6bdf7d1b1ece2588ccadd.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv 16 \cdot 96 \cdot 36 \cdot 56 \cdot 16 \cdot 36 \cdot 56 \cdot 2 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/58df2403da7cc85bef8347182c558ec7.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv (16 \cdot 96) \cdot (36 \cdot 56) \cdot (16 \cdot 36) \cdot (56 \cdot 2) \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/057533ec00048c90b5507cb3d8e6a7e4.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv 36 \cdot 16 \cdot 76 \cdot 12 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/a50737ddd2b7b04f5f95e8615b7f732b.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv (36 \cdot 16) \cdot (76 \cdot 12) \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/43e13cf99e16965b63c33558c6373d22.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv 76 \cdot 12 \pmod{100}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/4bc00c0fdc16433dda22cba55e333761.png' alt='\mbox{\footnotesize{\displaystyle{2^{2009} \equiv \textbf{12} \pmod{100}}}}'/></li>
</ul>
</li>
</ol>
<p>(I could have used negative numbers in the intermediate steps to make the math easier; for example, -4 instead of 96. Both are congruent mod 100.)</p>
<h2>3. Cyclic Powers</h2>
<p>In this method, you exploit the fact that the <a title="Read Rick Regan's Article “Patterns in the Last Digits of the Positive Powers of Two" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-two/">ending m digits of the positive powers of two repeat in cycles</a>; specifically, cycles of length 4&middot;5<sup>m-1</sup>, starting at 2<sup>m</sup>. Powers of two that differ in their exponents by 4&middot;5<sup>m-1</sup> have the same ending m digits.</p>
<p>There are two ways to use the cycle information, in techniques I call the <strong>table method</strong> and the <strong>base power method</strong>.</p>
<h4>Table Method</h4>
<p>In the table method, you compute the powers of two mod 10<sup>m</sup> in sequence, until the ending digits cycle. You label entries sequentially starting at m, wrapping around 0 to end at m &#8211; 1. I&#8217;ve created <a title="Read Rick Regan's Article “Patterns in the Last Digits of the Positive Powers of Two" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-two/">tables for the last one, two, and three ending digits</a>; in other words, tables for powers of two mod 10, mod 100, and mod 1000.</p>
<p>To find where in the cycle your power 2<sup>n</sup> falls, compute n mod 4&middot;5<sup>m-1</sup>, or equivalently, find the remainder of n/(4&middot;5<sup>m-1</sup>). The last m digits of 2<sup>n</sup> are the digits in the table with the label corresponding to that remainder.</p>
<p>For example, let&#8217;s find the last digit of 2<sup>2009</sup>. The last digit of the positive powers of two cycles with length 4, and <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/61883ebd4555f7efa9bab69506eb0f08.png' alt='\mbox{\footnotesize{\displaystyle{2009 \equiv 1 \pmod{4}}}}'/>. According to the table, a remainder of 1 corresponds to a last digit of 2.</p>
<p>Almost as simply, we can find the last <em>two</em> digits of 2<sup>2009</sup>. The last two digits of the positive powers of two cycle with length 20, and <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/5db11aa4241cdd2cb2a0499556a6c5c7.png' alt='\mbox{\footnotesize{\displaystyle{2009 \equiv 9 \pmod{20}}}}'/>. According to the table, a remainder of 9 corresponds to the ending digits 12.</p>
<h3>Finding the Last m Digits</h3>
<p>The table method works for any number of ending digits, but beyond two or three, is impractical. The tables grow large, by a factor of five for each additional ending digit.</p>
<h4>Base Power Method</h4>
<p>Every power of two 2<sup>n</sup>, mod 10<sup>m</sup>, is congruent to some power of two in the first instance of the cycle; that is, a power of two between 2<sup>m</sup> and 2<sup>(m + 4&middot;5<sup>m &#8211; 1</sup> &#8211; 1)</sup>. You need to determine which power of two in this range it is &#8212; what I call the <em>base</em> power of two &#8212; and then use another method to find its ending digits.</p>
<p>You can find the base power of two directly: it is 2<sup>m + j</sup>, where j is an offset given by the expression n-m (mod 4&middot;5<sup>m-1</sup>).</p>
<p>For example, let&#8217;s find the last digit of 2<sup>2009</sup>. <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/81d2f55a3fe9cc48783c29d235ff1953.png' alt='\mbox{\footnotesize{\displaystyle{2009 $-$ 1 \equiv 0 \pmod{4}}}}'/>, so the base power of two is 2<sup>1+0</sup> = 2<sup>1</sup> = 2. Trivially, we can see the ending digit is 2.</p>
<p>For the last two digits of 2<sup>2009</sup>, compute <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/how-to-find-the-last-digits-of-a-positive-power-of-two/59b43e1c3e2b07d9956b798f9922345c.png' alt='\mbox{\footnotesize{\displaystyle{2009 $-$ 2 \equiv 7 \pmod{20}}}}'/>. The base power of two is 2<sup>2+7</sup> = 2<sup>9</sup>, which is small enough to compute directly: 512. The last two digits are 12.</p>
<h3>Finding the Last m Digits</h3>
<p>The base power method works well for any number of ending digits, assuming n is greater than 4&middot;5<sup>m-1</sup>.</p>
<h2>Cheating</h2>
<p>I said find the last digits <em>without</em> using a computer, right? I wanted to verify my work, so I used <a href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/" title="Read Rick Regan's Article &ldquo;Exploring Binary Numbers With PARI/GP Calculator&rdquo;">PARI/GP</a> to compute 2<sup>2009</sup>. It took an instant &#8212; here it is:</p>
<p>58,784,291,598,041,831,640,721,059,900,297,317,581,942,666,346,941,194,264,<br />
455,308,125,479,232,583,289,360,069,460,965,699,405,121,019,824,433,389,516,<br />
158,094,000,492,490,796,188,432,969,007,685,435,732,643,092,034,554,442,399,<br />
887,360,352,654,923,898,902,974,171,610,618,912,504,957,328,187,117,386,950,<br />
842,341,026,317,332,718,773,233,103,358,237,779,148,190,179,650,358,079,135,<br />
564,562,516,081,648,810,332,848,214,481,400,042,754,868,418,296,221,651,998,<br />
157,278,605,568,219,649,390,953,792,425,227,268,163,704,976,021,381,769,156,<br />
258,409,778,685,642,966,081,035,151,287,502,869,585,844,829,824,788,935,390,<br />
157,871,063,324,138,385,197,912,084,049,961,962,094,914,858,370,754,777,898,<br />
867,719,950,514,578,646,749,211,908,564,621,201,347,904,089,822,990,746,021,<br />
295,498,658,798,312,326,238,643,788,303,040,5<span class="highlight_gray3">12</span></p>
<h2>Summary</h2>
<p>The three methods I&#8217;ve shown are efficient ways to do modular exponentiation, unlike the straightforward method, which requires n-1 multiplications to compute 2<sup>n</sup> mod 10<sup>m</sup>. The three methods provide shortcuts to the answer, exploiting knowledge of the laws of exponents and the cycling of ending digits.</p>
<p>Which method should you use? The ad hoc method is the least systematic but allows for case-by-case optimization. The method of successive squaring is the most systematic but may be overkill for certain problems. Learn all three methods to get a deeper understanding, then decide which one you like.</p>
<p>For finding the last digit, <strong>I like the ad hoc powers of six method</strong>. It is the quickest.</p>
<h2>Exercises</h2>
<p>For these exercises, use any method you like &#8212; or all three if you&#8217;re feeling ambitious:</p>
<ol>
<li>Find the last digit of 2<sup>497</sup></li>
<li>Find the last digit of 2<sup>20000</sup></li>
<li>Find the last two digits of 2<sup>613</sup></li>
<li>Find the last two digits of 2<sup>512</sup></li>
<li>Find the last three digits of 2<sup>129</sup></li>
<li>Find the last three digits of 2<sup>2009</sup></li>
</ol>
<h3>Answers</h3>
<ol>
<li>2</li>
<li>6</li>
<li>92</li>
<li>96</li>
<li>912</li>
<li>512</li>
</ol>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/how-to-find-the-last-digits-of-a-positive-power-of-two/">How to Find the Last Digits of a Positive Power of Two</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/how-to-find-the-last-digits-of-a-positive-power-of-two/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Patterns in the Last Digits of the Positive Powers of Two</title>
		<link>http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-two/</link>
		<comments>http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-two/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 19:02:02 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Exponents]]></category>
		<category><![CDATA[Modular arithmetic]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=249</guid>
		<description><![CDATA[The positive powers of two &#8212; 2, 4, 8, 16, 32, 64, 128, 256, &#8230; &#8212; follow an obvious repeating pattern in their ending digit: 2, 4, 8, 6, 2, 4, 8, 6, &#8230; . This cycle of four digits continues forever. There are also cycles beyond the last digit &#8212; in the last m [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-two/">Patterns in the Last Digits of the Positive Powers of Two</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The positive <a href="http://www.exploringbinary.com/the-powers-of-two/" title="Read Rick Regan's Article &ldquo;The Powers of Two&rdquo;">powers of two</a> &#8212; 2, 4, 8, 16, 32, 64, 128, 256, &#8230; &#8212; follow an obvious repeating pattern in their ending digit: 2, 4, 8, 6, 2, 4, 8, 6, &#8230; . This cycle of four digits continues forever. There are also cycles beyond the last digit &#8212; in the last <em>m</em> digits in fact &#8212; in the powers of two from 2<sup>m</sup> on. For example, the last two digits repeat in a cycle of length 20 starting with 04, and the last three digits repeat in a cycle of length 100 starting with 008.</p>
<p>In this article, I will show you why these cycles exist, how long they are, how they are expressed mathematically, and how to visualize them.</p>
<p><span id="more-249"></span></p>
<h2>Cycle in the Last Digit</h2>
<p>The last digit &#8212; the ones place &#8212; of a decimal integer d is the remainder of the division d/10. Equivalently, the last digit is the result of the operation <em>d </em><a title="Wikipedia article on modular arithmetic" href="http://en.wikipedia.org/wiki/Modular_arithmetic"><em>mod</em></a><em> 10</em>, when following the convention that the least nonnegative value &#8212; the <a title="Wolfram MathWorld definition of common residue" href="http://mathworld.wolfram.com/CommonResidue.html">common residue</a> &#8212; is returned. Modular arithmetic, combined with iterative generation of the <a title="Read Rick Regan's Article “A Table of Nonnegative Powers of Two” (positive powers of two start at 2)" href="http://www.exploringbinary.com/a-table-of-nonnegative-powers-of-two/">positive powers of two</a>, allows us to show the cycle in the last digit:</p>
<ol>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/39772fc9836698847a1f8f5d7307dde4.png' alt='\mbox{\footnotesize{\displaystyle{2^1 \equiv \textbf{2} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/a062d5f1fe0f3d35b74d3709e13ce3ed.png' alt='\mbox{\footnotesize{\displaystyle{2^2 \equiv 2^1 \cdot 2 \equiv 2 \cdot 2 \equiv \textbf{4} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/3d454bf1451e60ba2deac0695f5a15a3.png' alt='\mbox{\footnotesize{\displaystyle{2^3 \equiv 2^2 \cdot 2 \equiv 4 \cdot 2 \equiv \textbf{8} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/4601463cf8cbe43444b17c70c0410a17.png' alt='\mbox{\footnotesize{\displaystyle{2^4 \equiv 2^3 \cdot 2 \equiv 8 \cdot 2 \equiv \textbf{6} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/889310671cb6b3ef41b1a81e744ba547.png' alt='\mbox{\footnotesize{\displaystyle{2^5 \equiv 2^4 \cdot 2 \equiv 6 \cdot 2 \equiv \textbf{2} \pmod{10}}}}'/></li>
<li><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/e538e69b40f2ca5662403e1131b15960.png' alt='\mbox{\footnotesize{\displaystyle{2^6 \equiv 2^5 \cdot 2 \equiv 2 \cdot 2 \equiv \textbf{4} \pmod{10}}}}'/></li>
<li>&#8230;</li>
</ol>
<p>We start with 2, compute it mod 10, multiply that result by 2, compute <em>it</em> mod 10, etc. From this it&#8217;s clear the pattern will repeat, once a previous result &#8212; 2 in this case, at step 5 &#8212; is obtained. This shows that the numbers 2<sup>n</sup>, n &ge; 1, cycle through the four ending digits 2, 4, 8, and 6.</p>
<p>The cycle implies that powers of two with the same ending digit are related, their exponents differing by a multiple of four:</p>
<ul>
<li><strong>Ends in 2:</strong> 2<sup>1</sup>, 2<sup>5</sup>, 2<sup>9</sup>, 2<sup>13</sup>, 2<sup>17</sup>, &#8230; .</li>
<li><strong>Ends in 4:</strong> 2<sup>2</sup>, 2<sup>6</sup>, 2<sup>10</sup>, 2<sup>14</sup>, 2<sup>18</sup>, &#8230; .</li>
<li><strong>Ends in 8:</strong> 2<sup>3</sup>, 2<sup>7</sup>, 2<sup>11</sup>, 2<sup>15</sup>, 2<sup>19</sup>, &#8230; .</li>
<li><strong>Ends in 6:</strong> 2<sup>4</sup>, 2<sup>8</sup>, 2<sup>12</sup>, 2<sup>16</sup>, 2<sup>20</sup>, &#8230; .</li>
</ul>
<p>You can express these relationships more succinctly using the <a title="Read Rick Regan's Article “The Laws of Exponents”" href="http://www.exploringbinary.com/the-laws-of-exponents/">laws of exponents</a>, showing explicitly that the ending digit of the first four positive powers of two determine the ending digit of <em>all</em> positive powers of two:</p>
<ul>
<li><strong>Ends in 2:</strong> 2<sup>1</sup>&middot;2<sup>4k</sup>, or 2<sup>1+4k</sup>, k &ge; 0.</li>
<li><strong>Ends in 4:</strong> 2<sup>2</sup>&middot;2<sup>4k</sup>, or 2<sup>2+4k</sup>, k &ge; 0.</li>
<li><strong>Ends in 8:</strong> 2<sup>3</sup>&middot;2<sup>4k</sup>, or 2<sup>3+4k</sup>, k &ge; 0.</li>
<li><strong>Ends in 6:</strong> 2<sup>4</sup>&middot;2<sup>4k</sup>, or 2<sup>4+4k</sup>, k &ge; 0.</li>
</ul>
<p>You can also relate the positive powers of two to their ending digits based on their exponents (n) mod 4:</p>
<ul>
<li><strong>Ends in 2:</strong> <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/3a1a6e74fe0f350a6e70dfba503fb259.png' alt='\mbox{\footnotesize{\displaystyle{n \equiv 1 \pmod{4}}}}'/></li>
<li><strong>Ends in 4:</strong> <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/bd2a7eea7a9f666db8fb09f5002ec36b.png' alt='\mbox{\footnotesize{\displaystyle{n \equiv 2 \pmod{4}}}}'/></li>
<li><strong>Ends in 8:</strong> <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/ba0a84825349e2306e5d8e8fbf046108.png' alt='\mbox{\footnotesize{\displaystyle{n \equiv 3 \pmod{4}}}}'/></li>
<li><strong>Ends in 6:</strong> <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/0c780af817e6bc257882dadc85dd6f58.png' alt='\mbox{\footnotesize{\displaystyle{n \equiv 0 \pmod{4}}}}'/></li>
</ul>
<p>This gives an easy way to determine the last digit of any positive power of two. For example, the last digit of 2<sup>319</sup> is 8, since <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/ba74e8dc9514b856472896a09dd0ff37.png' alt='\mbox{\footnotesize{\displaystyle{319 \equiv 3 \pmod{4}}}}'/>.</p>
<table class="center" border="1" summary="Cycle in the last digit of the positive powers of 2">
<caption><strong>Cycle in the Last Digit of 2<sup>n</sup>, n&ge;1</strong></caption>
<tbody>
<tr>
<th class="center">Power of Two (k &ge; 0)</th>
<th class="center">Exponent (mod 4)</th>
<th class="center">Last Digit</th>
</tr>
<tr>
<td class="center">2<sup>1+4k</sup></td>
<td class="center">1</td>
<td class="center">2</td>
</tr>
<tr>
<td class="center">2<sup>2+4k</sup></td>
<td class="center">2</td>
<td class="center">4</td>
</tr>
<tr>
<td class="center">2<sup>3+4k</sup></td>
<td class="center">3</td>
<td class="center">8</td>
</tr>
<tr>
<td class="center">2<sup>4+4k</sup></td>
<td class="center">0</td>
<td class="center">6</td>
</tr>
</tbody>
</table>
<p>In summary, the table says that if <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/f02bfeb194caa11051c0946b4a0df5c3.png' alt='\mbox{\footnotesize{\displaystyle{x \equiv y \pmod{4}}}}'/>, <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/patterns-in-the-last-digits-of-the-positive-powers-of-two/95e148f2b0cb83ded08211c8f93c44ee.png' alt='\mbox{\footnotesize{\displaystyle{2^x \equiv 2^y \pmod{10}}}}'/>. </p>
<h2>Cycle in the Last Two Digits</h2>
<p>A similar analysis, but using <strong>mod 100</strong>, shows that the <strong>last two digits</strong> of the powers of two, <strong>starting at 2<sup>2</sup></strong>, cycle with a <strong>period of 20</strong>:</p>
<table class="center" border="1" summary="Cycle of the last 2 digits of the positive powers of 2">
<caption><strong>Cycle in the Last Two Digits of 2<sup>n</sup>, n&ge;2</strong></caption>
<tbody>
<tr>
<th class="center">Power of Two (k &ge; 0)</th>
<th class="center">Exponent (mod 20)</th>
<th class="center">Last 2 Digits</th>
</tr>
<tr>
<td class="center">2<sup>2+20k</sup></td>
<td class="center">2</td>
<td class="center">04</td>
</tr>
<tr>
<td class="center">2<sup>3+20k</sup></td>
<td class="center">3</td>
<td class="center">08</td>
</tr>
<tr>
<td class="center">2<sup>4+20k</sup></td>
<td class="center">4</td>
<td class="center">16</td>
</tr>
<tr>
<td class="center">2<sup>5+20k</sup></td>
<td class="center">5</td>
<td class="center">32</td>
</tr>
<tr>
<td class="center">2<sup>6+20k</sup></td>
<td class="center">6</td>
<td class="center">64</td>
</tr>
<tr>
<td class="center">2<sup>7+20k</sup></td>
<td class="center">7</td>
<td class="center">28</td>
</tr>
<tr>
<td class="center">2<sup>8+20k</sup></td>
<td class="center">8</td>
<td class="center">56</td>
</tr>
<tr>
<td class="center">2<sup>9+20k</sup></td>
<td class="center">9</td>
<td class="center">12</td>
</tr>
<tr>
<td class="center">2<sup>10+20k</sup></td>
<td class="center">10</td>
<td class="center">24</td>
</tr>
<tr>
<td class="center">2<sup>11+20k</sup></td>
<td class="center">11</td>
<td class="center">48</td>
</tr>
<tr>
<td class="center">2<sup>12+20k</sup></td>
<td class="center">12</td>
<td class="center">96</td>
</tr>
<tr>
<td class="center">2<sup>13+20k</sup></td>
<td class="center">13</td>
<td class="center">92</td>
</tr>
<tr>
<td class="center">2<sup>14+20k</sup></td>
<td class="center">14</td>
<td class="center">84</td>
</tr>
<tr>
<td class="center">2<sup>15+20k</sup></td>
<td class="center">15</td>
<td class="center">68</td>
</tr>
<tr>
<td class="center">2<sup>16+20k</sup></td>
<td class="center">16</td>
<td class="center">36</td>
</tr>
<tr>
<td class="center">2<sup>17+20k</sup></td>
<td class="center">17</td>
<td class="center">72</td>
</tr>
<tr>
<td class="center">2<sup>18+20k</sup></td>
<td class="center">18</td>
<td class="center">44</td>
</tr>
<tr>
<td class="center">2<sup>19+20k</sup></td>
<td class="center">19</td>
<td class="center">88</td>
</tr>
<tr>
<td class="center">2<sup>20+20k</sup></td>
<td class="center">0</td>
<td class="center">76</td>
</tr>
<tr>
<td class="center">2<sup>21+20k</sup></td>
<td class="center">1</td>
<td class="center">52</td>
</tr>
</tbody>
</table>
<h2>Cycle in the Last Three Digits</h2>
<p>To determine the cycle in the <strong>last three digits</strong>, repeat the same process using <strong>mod 1000</strong>. It shows that the powers of two, <strong>starting at 2<sup>3</sup></strong>, cycle with a <strong>period of 100</strong>:</p>
<table class="center" border="1" summary="Cycle of the last three digits of the positive powers of 2">
<caption><strong>Cycle in the Last Three Digits of 2<sup>n</sup>, n&ge;3</strong></caption>
<tbody>
<tr>
<th class="center">Power of Two (k &ge; 0)</th>
<th class="center">Exponent (mod 100)</th>
<th class="center">Last 3 Digits</th>
</tr>
<tr>
<td class="center">2<sup>3+100k</sup></td>
<td class="center">3</td>
<td class="center">008</td>
</tr>
<tr>
<td class="center">2<sup>4+100k</sup></td>
<td class="center">4</td>
<td class="center">016</td>
</tr>
<tr>
<td class="center">2<sup>5+100k</sup></td>
<td class="center">5</td>
<td class="center">032</td>
</tr>
<tr>
<td class="center">2<sup>6+100k</sup></td>
<td class="center">6</td>
<td class="center">064</td>
</tr>
<tr>
<td class="center">2<sup>7+100k</sup></td>
<td class="center">7</td>
<td class="center">128</td>
</tr>
<tr>
<td class="center">2<sup>8+100k</sup></td>
<td class="center">8</td>
<td class="center">256</td>
</tr>
<tr>
<td class="center">2<sup>9+100k</sup></td>
<td class="center">9</td>
<td class="center">512</td>
</tr>
<tr>
<td class="center">2<sup>10+100k</sup></td>
<td class="center">10</td>
<td class="center">024</td>
</tr>
<tr>
<td class="center">2<sup>11+100k</sup></td>
<td class="center">11</td>
<td class="center">048</td>
</tr>
<tr>
<td class="center">2<sup>12+100k</sup></td>
<td class="center">12</td>
<td class="center">096</td>
</tr>
<tr>
<td class="center">2<sup>13+100k</sup></td>
<td class="center">13</td>
<td class="center">192</td>
</tr>
<tr>
<td class="center">2<sup>14+100k</sup></td>
<td class="center">14</td>
<td class="center">384</td>
</tr>
<tr>
<td class="center">2<sup>15+100k</sup></td>
<td class="center">15</td>
<td class="center">768</td>
</tr>
<tr>
<td class="center">2<sup>16+100k</sup></td>
<td class="center">16</td>
<td class="center">536</td>
</tr>
<tr>
<td class="center">2<sup>17+100k</sup></td>
<td class="center">17</td>
<td class="center">072</td>
</tr>
<tr>
<td class="center">2<sup>18+100k</sup></td>
<td class="center">18</td>
<td class="center">144</td>
</tr>
<tr>
<td class="center">2<sup>19+100k</sup></td>
<td class="center">19</td>
<td class="center">288</td>
</tr>
<tr>
<td class="center">2<sup>20+100k</sup></td>
<td class="center">20</td>
<td class="center">576</td>
</tr>
<tr>
<td class="center">2<sup>21+100k</sup></td>
<td class="center">21</td>
<td class="center">152</td>
</tr>
<tr>
<td class="center">2<sup>22+100k</sup></td>
<td class="center">22</td>
<td class="center">304</td>
</tr>
<tr>
<td class="center">2<sup>23+100k</sup></td>
<td class="center">23</td>
<td class="center">608</td>
</tr>
<tr>
<td class="center">2<sup>24+100k</sup></td>
<td class="center">24</td>
<td class="center">216</td>
</tr>
<tr>
<td class="center">2<sup>25+100k</sup></td>
<td class="center">25</td>
<td class="center">432</td>
</tr>
<tr>
<td class="center">2<sup>26+100k</sup></td>
<td class="center">26</td>
<td class="center">864</td>
</tr>
<tr>
<td class="center">2<sup>27+100k</sup></td>
<td class="center">27</td>
<td class="center">728</td>
</tr>
<tr>
<td class="center">2<sup>28+100k</sup></td>
<td class="center">28</td>
<td class="center">456</td>
</tr>
<tr>
<td class="center">2<sup>29+100k</sup></td>
<td class="center">29</td>
<td class="center">912</td>
</tr>
<tr>
<td class="center">2<sup>30+100k</sup></td>
<td class="center">30</td>
<td class="center">824</td>
</tr>
<tr>
<td class="center">2<sup>31+100k</sup></td>
<td class="center">31</td>
<td class="center">648</td>
</tr>
<tr>
<td class="center">2<sup>32+100k</sup></td>
<td class="center">32</td>
<td class="center">296</td>
</tr>
<tr>
<td class="center">2<sup>33+100k</sup></td>
<td class="center">33</td>
<td class="center">592</td>
</tr>
<tr>
<td class="center">2<sup>34+100k</sup></td>
<td class="center">34</td>
<td class="center">184</td>
</tr>
<tr>
<td class="center">2<sup>35+100k</sup></td>
<td class="center">35</td>
<td class="center">368</td>
</tr>
<tr>
<td class="center">2<sup>36+100k</sup></td>
<td class="center">36</td>
<td class="center">736</td>
</tr>
<tr>
<td class="center">2<sup>37+100k</sup></td>
<td class="center">37</td>
<td class="center">472</td>
</tr>
<tr>
<td class="center">2<sup>38+100k</sup></td>
<td class="center">38</td>
<td class="center">944</td>
</tr>
<tr>
<td class="center">2<sup>39+100k</sup></td>
<td class="center">39</td>
<td class="center">888</td>
</tr>
<tr>
<td class="center">2<sup>40+100k</sup></td>
<td class="center">40</td>
<td class="center">776</td>
</tr>
<tr>
<td class="center">2<sup>41+100k</sup></td>
<td class="center">41</td>
<td class="center">552</td>
</tr>
<tr>
<td class="center">2<sup>42+100k</sup></td>
<td class="center">42</td>
<td class="center">104</td>
</tr>
<tr>
<td class="center">2<sup>43+100k</sup></td>
<td class="center">43</td>
<td class="center">208</td>
</tr>
<tr>
<td class="center">2<sup>44+100k</sup></td>
<td class="center">44</td>
<td class="center">416</td>
</tr>
<tr>
<td class="center">2<sup>45+100k</sup></td>
<td class="center">45</td>
<td class="center">832</td>
</tr>
<tr>
<td class="center">2<sup>46+100k</sup></td>
<td class="center">46</td>
<td class="center">664</td>
</tr>
<tr>
<td class="center">2<sup>47+100k</sup></td>
<td class="center">47</td>
<td class="center">328</td>
</tr>
<tr>
<td class="center">2<sup>48+100k</sup></td>
<td class="center">48</td>
<td class="center">656</td>
</tr>
<tr>
<td class="center">2<sup>49+100k</sup></td>
<td class="center">49</td>
<td class="center">312</td>
</tr>
<tr>
<td class="center">2<sup>50+100k</sup></td>
<td class="center">50</td>
<td class="center">624</td>
</tr>
<tr>
<td class="center">2<sup>51+100k</sup></td>
<td class="center">51</td>
<td class="center">248</td>
</tr>
<tr>
<td class="center">2<sup>52+100k</sup></td>
<td class="center">52</td>
<td class="center">496</td>
</tr>
<tr>
<td class="center">2<sup>53+100k</sup></td>
<td class="center">53</td>
<td class="center">992</td>
</tr>
<tr>
<td class="center">2<sup>54+100k</sup></td>
<td class="center">54</td>
<td class="center">984</td>
</tr>
<tr>
<td class="center">2<sup>55+100k</sup></td>
<td class="center">55</td>
<td class="center">968</td>
</tr>
<tr>
<td class="center">2<sup>56+100k</sup></td>
<td class="center">56</td>
<td class="center">936</td>
</tr>
<tr>
<td class="center">2<sup>57+100k</sup></td>
<td class="center">57</td>
<td class="center">872</td>
</tr>
<tr>
<td class="center">2<sup>58+100k</sup></td>
<td class="center">58</td>
<td class="center">744</td>
</tr>
<tr>
<td class="center">2<sup>59+100k</sup></td>
<td class="center">59</td>
<td class="center">488</td>
</tr>
<tr>
<td class="center">2<sup>60+100k</sup></td>
<td class="center">60</td>
<td class="center">976</td>
</tr>
<tr>
<td class="center">2<sup>61+100k</sup></td>
<td class="center">61</td>
<td class="center">952</td>
</tr>
<tr>
<td class="center">2<sup>62+100k</sup></td>
<td class="center">62</td>
<td class="center">904</td>
</tr>
<tr>
<td class="center">2<sup>63+100k</sup></td>
<td class="center">63</td>
<td class="center">808</td>
</tr>
<tr>
<td class="center">2<sup>64+100k</sup></td>
<td class="center">64</td>
<td class="center">616</td>
</tr>
<tr>
<td class="center">2<sup>65+100k</sup></td>
<td class="center">65</td>
<td class="center">232</td>
</tr>
<tr>
<td class="center">2<sup>66+100k</sup></td>
<td class="center">66</td>
<td class="center">464</td>
</tr>
<tr>
<td class="center">2<sup>67+100k</sup></td>
<td class="center">67</td>
<td class="center">928</td>
</tr>
<tr>
<td class="center">2<sup>68+100k</sup></td>
<td class="center">68</td>
<td class="center">856</td>
</tr>
<tr>
<td class="center">2<sup>69+100k</sup></td>
<td class="center">69</td>
<td class="center">712</td>
</tr>
<tr>
<td class="center">2<sup>70+100k</sup></td>
<td class="center">70</td>
<td class="center">424</td>
</tr>
<tr>
<td class="center">2<sup>71+100k</sup></td>
<td class="center">71</td>
<td class="center">848</td>
</tr>
<tr>
<td class="center">2<sup>72+100k</sup></td>
<td class="center">72</td>
<td class="center">696</td>
</tr>
<tr>
<td class="center">2<sup>73+100k</sup></td>
<td class="center">73</td>
<td class="center">392</td>
</tr>
<tr>
<td class="center">2<sup>74+100k</sup></td>
<td class="center">74</td>
<td class="center">784</td>
</tr>
<tr>
<td class="center">2<sup>75+100k</sup></td>
<td class="center">75</td>
<td class="center">568</td>
</tr>
<tr>
<td class="center">2<sup>76+100k</sup></td>
<td class="center">76</td>
<td class="center">136</td>
</tr>
<tr>
<td class="center">2<sup>77+100k</sup></td>
<td class="center">77</td>
<td class="center">272</td>
</tr>
<tr>
<td class="center">2<sup>78+100k</sup></td>
<td class="center">78</td>
<td class="center">544</td>
</tr>
<tr>
<td class="center">2<sup>79+100k</sup></td>
<td class="center">79</td>
<td class="center">088</td>
</tr>
<tr>
<td class="center">2<sup>80+100k</sup></td>
<td class="center">80</td>
<td class="center">176</td>
</tr>
<tr>
<td class="center">2<sup>81+100k</sup></td>
<td class="center">81</td>
<td class="center">352</td>
</tr>
<tr>
<td class="center">2<sup>82+100k</sup></td>
<td class="center">82</td>
<td class="center">704</td>
</tr>
<tr>
<td class="center">2<sup>83+100k</sup></td>
<td class="center">83</td>
<td class="center">408</td>
</tr>
<tr>
<td class="center">2<sup>84+100k</sup></td>
<td class="center">84</td>
<td class="center">816</td>
</tr>
<tr>
<td class="center">2<sup>85+100k</sup></td>
<td class="center">85</td>
<td class="center">632</td>
</tr>
<tr>
<td class="center">2<sup>86+100k</sup></td>
<td class="center">86</td>
<td class="center">264</td>
</tr>
<tr>
<td class="center">2<sup>87+100k</sup></td>
<td class="center">87</td>
<td class="center">528</td>
</tr>
<tr>
<td class="center">2<sup>88+100k</sup></td>
<td class="center">88</td>
<td class="center">056</td>
</tr>
<tr>
<td class="center">2<sup>89+100k</sup></td>
<td class="center">89</td>
<td class="center">112</td>
</tr>
<tr>
<td class="center">2<sup>90+100k</sup></td>
<td class="center">90</td>
<td class="center">224</td>
</tr>
<tr>
<td class="center">2<sup>91+100k</sup></td>
<td class="center">91</td>
<td class="center">448</td>
</tr>
<tr>
<td class="center">2<sup>92+100k</sup></td>
<td class="center">92</td>
<td class="center">896</td>
</tr>
<tr>
<td class="center">2<sup>93+100k</sup></td>
<td class="center">93</td>
<td class="center">792</td>
</tr>
<tr>
<td class="center">2<sup>94+100k</sup></td>
<td class="center">94</td>
<td class="center">584</td>
</tr>
<tr>
<td class="center">2<sup>95+100k</sup></td>
<td class="center">95</td>
<td class="center">168</td>
</tr>
<tr>
<td class="center">2<sup>96+100k</sup></td>
<td class="center">96</td>
<td class="center">336</td>
</tr>
<tr>
<td class="center">2<sup>97+100k</sup></td>
<td class="center">97</td>
<td class="center">672</td>
</tr>
<tr>
<td class="center">2<sup>98+100k</sup></td>
<td class="center">98</td>
<td class="center">344</td>
</tr>
<tr>
<td class="center">2<sup>99+100k</sup></td>
<td class="center">99</td>
<td class="center">688</td>
</tr>
<tr>
<td class="center">2<sup>100+100k</sup></td>
<td class="center">0</td>
<td class="center">376</td>
</tr>
<tr>
<td class="center">2<sup>101+100k</sup></td>
<td class="center">1</td>
<td class="center">752</td>
</tr>
<tr>
<td class="center">2<sup>102+100k</sup></td>
<td class="center">2</td>
<td class="center">504</td>
</tr>
</tbody>
</table>
<h2>Cycle in the Last m Digits</h2>
<p>The last m digits of a positive power of two are taken mod 10<sup>m</sup>, and have a cycle of period 4&middot;5<sup>m-1</sup>, starting at 2<sup>m</sup>. (The <a title="Read Rick Regan's Article &ldquo;Cycle Length of Powers of Two Mod Powers of Ten&rdquo;" href="http://www.exploringbinary.com/cycle-length-of-powers-of-two-mod-powers-of-ten/">proof</a> involves techniques of number theory, and is beyond the scope of this article.)</p>
<table class="center" border="1" summary="Cycle Length for Number of Ending Digits (1 to 10)">
<caption><strong>Cycle Length for Number of Ending Digits (1 to 10)</strong></caption>
<tbody>
<tr>
<th class="center">m</th>
<th class="center">Period (4&middot;5<sup>m-1</sup>)</th>
<th class="center">Starts with</th>
</tr>
<tr>
<td class="center">1</td>
<td class="right">4</td>
<td class="right">2<sup>1</sup></td>
</tr>
<tr>
<td class="center">2</td>
<td class="right">20</td>
<td class="right">2<sup>2</sup></td>
</tr>
<tr>
<td class="center">3</td>
<td class="right">100</td>
<td class="right">2<sup>3</sup></td>
</tr>
<tr>
<td class="center">4</td>
<td class="right">500</td>
<td class="right">2<sup>4</sup></td>
</tr>
<tr>
<td class="center">5</td>
<td class="right">2500</td>
<td class="right">2<sup>5</sup></td>
</tr>
<tr>
<td class="center">6</td>
<td class="right">12500</td>
<td class="right">2<sup>6</sup></td>
</tr>
<tr>
<td class="center">7</td>
<td class="right">62500</td>
<td class="right">2<sup>7</sup></td>
</tr>
<tr>
<td class="center">8</td>
<td class="right">312500</td>
<td class="right">2<sup>8</sup></td>
</tr>
<tr>
<td class="center">9</td>
<td class="right">1562500</td>
<td class="right">2<sup>9</sup></td>
</tr>
<tr>
<td class="center">10</td>
<td class="right">7812500</td>
<td class="right">2<sup>10</sup></td>
</tr>
</tbody>
</table>
<p>The periods grow very fast &#8212; exponentially &#8212; so it is impractical to list tables of ending digits for m greater than three.</p>
<h2>Nesting of Cycles</h2>
<p>The cycles in m digit, m-1 digit, m-2 digit, &#8230;, 1 digit endings can be viewed as nested, even though their starting points are staggered. You just have shift the starting points of the lesser digit cycles to make them coincide. </p>
<p>For example, one copy of the length 100 cycle of three digit endings has within it five copies of the length 20 cycle of two digit endings; one copy of the length 20 cycle of two digit endings has within it five copies of the length 4 cycle of one digit endings. This works when you view the one digit ending cycle as starting at 8 (shifted two positions), the two digit ending cycle as starting at 08 (shifted one position), and the three digit ending cycle as starting at 008 (not shifted).</p>
<p>The diagram below shows the nesting by shading every other occurrence of a cycle (the 100s place is fully shaded, because only 100 powers of two &#8212; one cycle of the last three ending digits &#8212; are shown).</p>
<div class="wp-caption aligncenter" style="width: 358px"><img src="http://www.exploringbinary.com/wp-content/uploads/PosPO2EndingDigits.jpg" alt="Nested 1-3 Digit Ending Patterns in Powers of Two from 2^3 to 2^102" width="348" height="1046"/><p class="wp-caption-text">Nested 1-3 Digit Ending Patterns From 2<sup>3</sup> to 2<sup>102</sup></p></div>
<h2>Exploring Ending Digits with PARI/GP</h2>
<p>I used <a href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/" title="Read Rick Regan's Article &ldquo;Exploring Binary Numbers With PARI/GP Calculator&rdquo;">PARI/GP</a> to make some of the calculations above and to check my work.  Here are three examples:</p>
<ul>
<li><strong>Print the first 20 powers of two that end in 2</strong>:
<pre>
? <strong>for (i=0,19,print(&quot;2^&quot;,1+4*i,&quot;: &quot;,2^(1+4*i)))</strong>
2^1: 2
2^5: 32
2^9: 512
2^13: 8192
2^17: 131072
2^21: 2097152
2^25: 33554432
2^29: 536870912
2^33: 8589934592
2^37: 137438953472
2^41: 2199023255552
2^45: 35184372088832
2^49: 562949953421312
2^53: 9007199254740992
2^57: 144115188075855872
2^61: 2305843009213693952
2^65: 36893488147419103232
2^69: 590295810358705651712
2^73: 9444732965739290427392
2^77: 151115727451828646838272
</pre>
</li>
<li><strong>Print the cycle of the last two digits</strong> (the &#8216;%&#8217; operator returns the remainder, which in effect is how we&#8217;re using modular arithmetic):
<pre>
? <strong>for (i=2,21,print(&quot;2^&quot;,i,&quot; mod(100): &quot;,2^i % 100))</strong>
2^2 mod(100): 4
2^3 mod(100): 8
2^4 mod(100): 16
2^5 mod(100): 32
2^6 mod(100): 64
2^7 mod(100): 28
2^8 mod(100): 56
2^9 mod(100): 12
2^10 mod(100): 24
2^11 mod(100): 48
2^12 mod(100): 96
2^13 mod(100): 92
2^14 mod(100): 84
2^15 mod(100): 68
2^16 mod(100): 36
2^17 mod(100): 72
2^18 mod(100): 44
2^19 mod(100): 88
2^20 mod(100): 76
2^21 mod(100): 52
</pre>
<p>(Single-digit results have an implicit leading 0.)</p>
</li>
<li><strong>Print the period of the last 1 to 10 digits</strong>:
<pre>
? <strong>for (i=1,10,print(i,&quot;: &quot;,4*5^(i-1)))</strong>
1: 4
2: 20
3: 100
4: 500
5: 2500
6: 12500
7: 62500
8: 312500
9: 1562500
10: 7812500
</pre>
</li>
</ul>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-two/">Patterns in the Last Digits of the Positive Powers of Two</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-two/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Exploring Binary Numbers With PARI/GP Calculator</title>
		<link>http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/</link>
		<comments>http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 21:12:37 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Convert to binary]]></category>
		<category><![CDATA[Convert to decimal]]></category>
		<category><![CDATA[Decimals]]></category>
		<category><![CDATA[Exponents]]></category>
		<category><![CDATA[Fractions]]></category>
		<category><![CDATA[Geometric series]]></category>
		<category><![CDATA[Pascal's triangle]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=244</guid>
		<description><![CDATA[PARI/GP is an open source computer algebra system I use frequently in my study of binary numbers. It doesn&#8217;t manipulate binary numbers directly &#8212; input, and most output, is in decimal &#8212; so I use it mainly to do the next best thing: calculate with powers of two. Calculations with powers of two are, indirectly, [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/">Exploring Binary Numbers With PARI/GP Calculator</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a title="PARI/GP" href="http://pari.math.u-bordeaux.fr/">PARI/GP</a> is an open source <a title="Wikipedia article defining computer algebra system" href="http://en.wikipedia.org/wiki/Computer_algebra_system">computer algebra system</a> I use frequently in my study of binary numbers. It doesn&#8217;t manipulate binary numbers directly &#8212; input, and most output, is in decimal &#8212; so I use it mainly to do the next best thing: calculate with <a href="http://www.exploringbinary.com/the-powers-of-two/" title="Read Rick Regan's Article &ldquo;The Powers of Two&rdquo;">powers of two</a>. Calculations with powers of two are, indirectly, calculations with binary numbers.</p>
<p>PARI/GP is a sophisticated tool, with several components &#8212; yet <a href="http://www.exploringbinary.com/how-to-install-and-run-pari-gp-calculator-on-windows/" title="Read Rick Regan's Article &ldquo;How to Install and Run PARI/GP Calculator on Windows&rdquo;">it&#8217;s easy to install and use</a>. I use its command shell in particular, the PARI/GP calculator, or <strong>gp</strong> for short. I will show you how to use simple gp commands to explore binary numbers.</p>
<div class="wp-caption aligncenter" style="width: 534px"><img src="http://www.exploringbinary.com/wp-content/uploads/PARI-gp-example.jpg" alt="PARI/GP Calculator (Example Calculations) (My Setup on Windows)" width="524" height="290"/><p class="wp-caption-text">PARI/GP Calculator (Sample of Calculations Used to Explore Binary Numbers)</p></div>
<p><span id="more-244"></span>In particular, I&#8217;ll show you how to:</p>
<ul>
<li><a title="Jump to section``Generate Arbitrarily Large or Small Powers of Two''" href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/#generate-powers-of-two">Generate arbitrarily large or small powers of two</a></li>
<li><a title="Jump to section``Check if an Integer is a Positive Power of Two''" href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/#check-power-of-two">Check if an integer is a positive power of two</a></li>
<li><a title="Jump to section``Sum Powers of Two''" href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/#sum-powers-of-two">Sum powers of two</a></li>
<li><a title="Jump to section``Find the Largest Power of Two Contained in a Number''" href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/#find-largest-power-of-two">Find the largest power of two contained in a number</a></li>
<li><a title="Jump to section``Convert Dyadic Decimals to Dyadic Fractions''" href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/#convert-decimal-to-dyadic">Convert dyadic decimals to dyadic fractions</a></li>
<li><a title="Jump to section``Discover Properties of Binary Representations''" href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/#properties-of-binary">Discover properties of binary representations</a>
<ul>
<li><a title="Jump to section``Convert Decimal to Binary''" href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/#convert-to-binary">Convert decimal to binary</a></li>
<li><a title="Jump to section``Count Number of Trailing Zeros''" href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/#count-trailing-zeros">Count number of trailing zeros</a></li>
<li><a title="Jump to section``Count Number of Bits''" href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/#count-bits">Count number of bits</a></li>
<li><a title="Jump to section``Count Number of 1 Bits''" href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/#count-one-bits">Count number of 1 bits</a></li>
</ul>
</li>
</ul>
<p class="break">In the sections that follow, I&#8217;ve chosen to show the text log of commands &#8212; formatted for display &#8212; rather than screenshots of the command shell.</p>
<h2><a name="generate-powers-of-two"></a>Generate Arbitrarily Large or Small Powers of Two</h2>
<h3>Nonnegative Powers of Two</h3>
<p>gp can generate any arbitrary <a title="Read Rick Regan's Article &ldquo;A Table of Nonnegative Powers of Two&rdquo;" href="http://www.exploringbinary.com/a-table-of-nonnegative-powers-of-two/">nonnegative power of two</a>:</p>
<pre>
? <strong>2^8</strong>
%1 = 256

? <strong>2^64</strong>
%2 = 18446744073709551616

? <strong>2^200</strong>
%3 = 1606938044258990275541962092341162602522202993782792835301376
</pre>
<p>gp can also generate sequences of nonnegative powers of two, from 2<sup>0</sup> to 2<sup>n</sup>: </p>
<pre>
? <strong>for(i=0,16,print(2^i))</strong>
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
</pre>
<p>There are also a few &#8220;fun&#8221; ways to generate sequences of nonnegative powers of two:</p>
<ul>
<li>By computing the divisors of 2<sup>n</sup>:
<pre>
? <strong>divisors(2^16)</strong>
%1 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096,
8192, 16384, 32768, 65536]
</pre>
</li>
<li>By computing the sum of each row, 0 through n, of Pascal&#8217;s Triangle:
<pre>
? <strong>for(i=0,16,print(sum(j=0,i,binomial(i,j))))</strong>
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
</pre>
</li>
<li>By computing the value of <a title="Wikipedia article on Euler's totient function" href="http://en.wikipedia.org/wiki/Euler%27s_totient_function">Euler&#8217;s phi function</a> for 2<sup>1</sup> through 2<sup>n+1</sup>:
<pre>
? <strong>for(i=0,16,print(eulerphi(2^(i+1))))</strong>
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
</pre>
</li>
<li>By computing the <a title="Read Rick Regan's Article &ldquo;Cycle Length of Powers of Five Mod Powers of Ten&rdquo;" href="http://www.exploringbinary.com/cycle-length-of-powers-of-five-mod-powers-of-ten/">order of 5 mod powers of two</a> for 2<sup>2</sup> through 2<sup>n+2</sup>:
<pre>
? <strong>for(i=0,16,print(znorder(Mod(5,2^(i+2)))))</strong>
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
</pre>
</li>
</ul>
<h3>Negative Powers of Two</h3>
<p>gp can generate any arbitrary <a title="Read Rick Regan's Article &ldquo;A Table of Negative Powers of Two&rdquo;" href="http://www.exploringbinary.com/a-table-of-negative-powers-of-two/">negative power of two</a>:</p>
<ul>
<li>In fraction form:
<pre>
? <strong>2^-16</strong>
%1 = 1/65536

? <strong>1/2^16</strong>
%2 = 1/65536
</pre>
</li>
<li>In decimal form:
<pre>
? <strong>2.^-16</strong>
%1 = 0.00001525878906250000000000000000

? <strong>1/2.^16</strong>
%2 = 0.00001525878906250000000000000000

? <strong>0.5^16</strong>
%3 = 0.00001525878906250000000000000000
</pre>
</li>
</ul>
<p>gp can also generate sequences of negative powers of two, from 2<sup>-1</sup> to 2<sup>-n</sup>, in fraction or decimal form:</p>
<pre>
? <strong>for(i=1,8,print(2^-i))</strong>
1/2
1/4
1/8
1/16
1/32
1/64
1/128
1/256

? <strong>for(i=1,8,print(2.^-i))</strong>
0.500000000000000000000000000000
0.250000000000000000000000000000
0.125000000000000000000000000000
0.0625000000000000000000000000000
0.0312500000000000000000000000000
0.0156250000000000000000000000000
0.00781250000000000000000000000000
0.00390625000000000000000000000000
</pre>
<h4>A Note on Precision</h4>
<p>When dealing with decimals, you have to make sure you are using the proper precision. The default precision, 28 significant decimal digits, is enough for the examples above &#8212; in fact, more than enough, as judged by the trailing 0s. </p>
<p>Here&#8217;s an example where the default precision is <em>not</em> enough:</p>
<pre>
? <strong>2.^-42</strong>
%1 = 0.0000000000002273736754432320594787597656
</pre>
<p>How do I know there&#8217;s not enough precision? First of all, the displayed answer has only 40 decimal places, and 2<sup>-42</sup> has 42 decimal places (2<sup>-n</sup> has n decimal places). Also, the displayed answer does not end with the digit &lsquo;5&rsquo;; <a title="Read Rick Regan's Article &ldquo;Patterns in the Last Digits of the Positive Powers of Five&rdquo;" href="http://www.exploringbinary.com/patterns-in-the-last-digits-of-the-positive-powers-of-five/">all negative powers of two must end in &lsquo;5&rsquo;</a>.</p>
<p>Here is 2<sup>-42</sup> again, printed with 42 significant digits using the &lsquo;<strong>&#92;p</strong>&rsquo; command:</p>
<pre>
? <strong>&#92;p 42</strong>
   realprecision = 48 significant digits (42 digits displayed)

? <strong>2.^-42</strong>
%1 = 0.000000000000227373675443232059478759765625000000000000
</pre>
<p> (PARI/GP sets its precision based on machine word boundaries, so the number of significant digits used for computation may be greater than the number of significant digits displayed.)</p>
<p>As you can see, we overshot &#8212; trailing 0s were added. Even though 2<sup>-42</sup> has 42 decimal places, it only has 30 significant digits; that is, 30 digits after the 12 leading 0s.</p>
<p>Here&#8217;s how to display 2<sup>-42</sup> exactly, without the trailing 0s:</p>
<pre>
? <strong>&#92;p 30</strong>
   realprecision = 38 significant digits (30 digits displayed)

? <strong>2.^-42</strong>
%1 = 0.000000000000227373675443232059478759765625
</pre>
<h2><a name="check-power-of-two"></a>Check if an Integer is a Positive Power of Two</h2>
<p><a href="http://www.exploringbinary.com/how-to-check-if-a-number-is-a-power-of-two/" title="Read Rick Regan's Article &ldquo;How to Check If a Number Is a Power of Two&rdquo;">An integer is a positive power of two if its only prime factor is 2</a>, as demonstrated by these examples:</p>
<pre>
? <strong>2^64</strong>
%1 = 18446744073709551616

? <strong>factor(18446744073709551616)</strong>
%2 =
[2 64]

? <strong>2^64-1</strong>
%3 = 18446744073709551615

? <strong>factor(18446744073709551615)</strong>
%4 =
[3 1]

[5 1]

[17 1]

[257 1]

[641 1]

[65537 1]

[6700417 1]
</pre>
<h2><a name="sum-powers-of-two"></a>Sum Powers of Two</h2>
<p>A binary number represents a sum of powers of two, so you can convert it to decimal simply by performing addition. </p>
<h3>Sum Nonnegative Powers of Two</h3>
<p>Converting binary integers to decimal is straightforward. For example, <a title="Read Rick Regan's Article &ldquo;One Hundred Cheerios in Binary&rdquo;" href="http://www.exploringbinary.com/one-hundred-cheerios-in-binary/">1100100<sub>2</sub>, which represents 2<sup>6</sup> + 2<sup>5</sup> + 2<sup>2</sup>, is 100<sub>10</sub></a>:</p>
<pre>
? <strong>2^6 + 2^5 + 2^2</strong>
%1 = 100
</pre>
<h3>Sum Negative Powers of Two</h3>
<p>Binary fractionals can be finite or infinite; converting finite binary fractionals to decimal is straightforward. For example, 0.101<sub>2</sub> is 5/8, or 0.625, in decimal:</p>
<pre>
? <strong>2^-1 + 2^-3</strong>
%1 = 5/8

? <strong>2.^-1 + 2^-3</strong>
%2 = 0.6250000000000000000000000000
</pre>
<p>0.111111<sub>2</sub> is 63/64, or 0.984375, in decimal:</p>
<pre>
? <strong>sum(i=1,6,2^-i)</strong>
%1 = 63/64

? <strong>sum(i=1,6,2.^-i)</strong>
%2 = 0.9843750000000000000000000000
</pre>
<p>Infinite binary fractionals are more involved; they require infinite sums of negative powers of two. To show a simple example, consider 0.0<span style="text-decoration:overline">1</span><sub>2</sub>. This represents an infinite geometric series of all negative powers of two except 2<sup>-1</sup>. It converges to 1/2:</p>
<p class="center"><img class='align_baseline' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/exploring-binary-numbers-with-parigp-calculator/0bc937161c23627d1c107e185cd728b7.png' alt='\mbox{\footnotesize{\displaystyle\sum_{i=2}^\infty 2^{-i} = \frac{1}{2}}}'/></p>
<p>(This is the same <a href="http://www.exploringbinary.com/about-the-header-image/" title="Read Rick Regan's Article &ldquo;About the Header Image&rdquo;">summation shown in this site&#8217;s header image</a>.)</p>
<pre>
? <strong>suminf(i=2,2^-i)</strong>
%1 = 0.5000000000000000000000000000
</pre>
<p>You can see the series converge by using finite sums, adding more terms each time:</p>
<pre>
? <strong>&#92;p 50</strong>
? <strong>sum(i=2,10,2.^-i)</strong>
%1 = 0.49902343750000000000000000000000000000000000000000

? <strong>sum(i=2,20,2.^-i)</strong>
%2 = 0.49999904632568359375000000000000000000000000000000

? <strong>sum(i=2,30,2.^-i)</strong>
%3 = 0.49999999906867742538452148437500000000000000000000

? <strong>sum(i=2,40,2.^-i)</strong>
%4 = 0.49999999999909050529822707176208496093750000000000

? <strong>sum(i=2,50,2.^-i)</strong>
%5 = 0.49999999999999911182158029987476766109466552734375
</pre>
<h2><a name="find-largest-power-of-two"></a>Find the Largest Power of Two Contained in a Number</h2>
<p>The largest power of two less than or equal to a positive integer n is 2 raised to the integer part of the base 2 logarithm of n; that is, 2<sup>floor(log<sub>2</sub>(n))</sup>, or <img class='align_top' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/exploring-binary-numbers-with-parigp-calculator/a1bcacfe6bc7d1e8771ea5569174ea7d.png' alt='\mbox{\footnotesize{\displaystyle{2^{\lfloor log_2(n) \rfloor}}}}'/>. This is used, for example, in the &#8220;subtract largest power of two&#8221; method of decimal to binary conversion, or in the <a href="http://www.exploringbinary.com/powers-of-two-in-the-josephus-problem/" title="Read Rick Regan's Article &ldquo;Powers Of Two In The Josephus Problem&rdquo;">formula for the solution to the Josephus Problem</a>.</p>
<p>PARI/GP doesn&#8217;t compute base 2 logarithms directly, so you have to do a <a title="Wikipedia article on logarithm change of base" href="http://en.wikipedia.org/wiki/Logarithm#Change_of_base">change of base</a>. For example, the largest power of two in 100 is:</p>
<pre>
? <strong>2^(floor(log(100)/log(2)))</strong>
%1 = 64
</pre>
<p>You have to be careful with larger numbers, especially those that are powers of two or close to one.  The logarithm function will require greater precision to give the correct result:</p>
<pre>
? <strong>n=2^50</strong>
%1 = 1125899906842624

? <strong>2^(floor(log(n)/log(2)))</strong>
%2 = 562949953421312

? <strong>&#92;p 100</strong>
   realprecision = 105 significant digits (100 digits displayed)

? <strong>2^(floor(log(n)/log(2)))</strong>
%3 = 1125899906842624
</pre>
<p>(I don&#8217;t know if there&#8217;s a systematic way to pick the exact precision required &#8212; I picked 100 digits arbitrarily, assuming it would be large enough.)</p>
<h2><a name="convert-decimal-to-dyadic"></a>Convert Dyadic Decimals to Dyadic Fractions</h2>
<p>A <a title="Wikipedia article on dyadic fraction" href="http://en.wikipedia.org/wiki/Dyadic_fraction">dyadic fraction</a> is a number that can be written in the form a/2<sup>n</sup>. For our purposes, a &lt; 2<sup>n</sup>, so it is simply a sum of negative powers of two. For example, 3/8 = 1/4 + 1/8.</p>
<p>A <em><strong>dyadic decimal</strong></em> is what I call a dyadic fraction in decimal form; for example, 0.375. A dyadic decimal can be converted to a dyadic fraction easily: just write it in the form b/10<sup>m</sup> and reduce to lowest terms. For example:</p>
<pre>
? <strong>375/1000</strong>
%1 = 3/8

? <strong>375/10^3</strong>
%2 = 3/8
</pre>
<p>PARI/GP reduces fractions to lowest terms automatically, so there&#8217;s nothing further to do.</p>
<p>For longer decimals, like those that represent double-precision floating-point numbers, it&#8217;s cumbersome &#8212; and error prone &#8212; to count decimal places by hand. I wrote this gp script to automate the process:</p>
<pre>
<strong>dyadic</strong>(decimal_num_string)=
{
 decimal_num = eval(decimal_num_string);
 decimal_den_exponent = length(decimal_num_string);
 decimal_den = 10^decimal_den_exponent;

 dyadic_num = numerator(decimal_num/decimal_den);
 dyadic_den = denominator(decimal_num/decimal_den);
 dyadic_den_exponent = valuation(dyadic_den,2);

 print(&quot;Decimal: 0.&quot;,decimal_num_string);
 print(&quot;Dyadic fraction: &quot;,dyadic_num,&quot;/2^&quot;,dyadic_den_exponent);
}
</pre>
<p>It takes as argument the <em>string</em> representation of the numerator of the dyadic fraction, which is just the dyadic decimal without the &#8220;0.&#8221; prefix (a string preserves leading 0s, which must be counted to determine the proper power of 10 denominator!). It computes the denominator that matches the length of the numerator and then divides the two. </p>
<p>The script has the added bonus of displaying the denominator in the form 2<sup>n</sup>, since large denominators are otherwise not readily identified as powers of two.</p>
<p>Here&#8217;s the script in action:</p>
<pre>
? <strong>&#92;r dyadic</strong>

? <strong>dyadic(&quot;375&quot;)</strong>
Decimal: 0.375
Dyadic fraction: 3/2^3

? <strong>2.^-8</strong>
%1 = 0.003906250000000000000000000000

? <strong>dyadic(&quot;00390625&quot;)</strong>
Decimal: 0.00390625
Dyadic fraction: 1/2^8

? <strong>dyadic(&quot;1000000000000000055511151231257827021181583404541015625&quot;)</strong>
Decimal: 0.1000000000000000055511151231257827021181583404541015625
Dyadic fraction: 3602879701896397/2^55

? <strong>dyadic(&quot;59999999999999997779553950749686919152736663818359375&quot;)</strong>
Decimal: 0.59999999999999997779553950749686919152736663818359375
Dyadic fraction: 5404319552844595/2^53
</pre>
<p>(You might recognize those last two examples as the double-precision floating-point approximations of the decimal values 0.1 and 0.6, respectively.)</p>
<h2><a name="properties-of-binary"></a>Discover Properties of Binary Representations</h2>
<p>You can discover properties of the binary representation of a number in two ways: directly, by converting it to binary and viewing the result, or indirectly, by doing calculations related to its underlying binary representation. PARI/GP lets you do both.</p>
<h3><a name="convert-to-binary"></a>Convert Decimal to Binary</h3>
<p>PARI/GP can convert integers to binary, although to an awkward format:</p>
<pre>
? <strong>binary(7)</strong>
%1 = [1, 1, 1]

? <strong>binary(2^50-1)</strong>
%2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1]
</pre>
<p>PARI/GP can also convert real numbers to binary, to an even more awkward format:</p>
<pre>
?<strong> binary(0.1)</strong>
%1 = [[0], [0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1]]

? <strong>binary(0.6)</strong>
%2 = [[0], [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0]]
</pre>
<p>You can&#8217;t tell from the output whether these are finite or infinite expansions, but we know in this case they are infinite: 0.1<sub>10</sub> is 0.0<span style="text-decoration:overline">0011</span><sub>2</sub>, and 0.6<sub>10</sub> is 0.<span style="text-decoration:overline">1001</span><sub>2</sub>. They are rounded to the nearest dyadic allowed with the given precision.</p>
<p>More bits are printed if you increase the precision with the &lsquo;<strong>&#92;p</strong>&rsquo; command.</p>
<h3><a name="count-trailing-zeros"></a>Count Number of Trailing Zeros</h3>
<p>You can determine the number of trailing zeros in the binary representation of an integer greater than one without first converting it to binary &#8212; all you need to do is factor it. If it has no factors of 2, it has no trailing zeros; if it has a factor of 2, it has a number of trailing zeros equal to the exponent to which 2 is raised.  For example, 100<sub>10</sub> = 1100100<sub>2</sub> has two trailing zeros:</p>
<pre>
? <strong>factor(100)</strong>
%1 =
[2 2]
[5 2]
</pre>
<p>The valuation function gives the same answer. It prints the exponent of 2 directly:</p>
<pre>
? <strong>valuation(100,2)</strong>
%1 = 2
</pre>
<h3><a name="count-bits"></a>Count Number of Bits</h3>
<p>The number of bits in the binary representation of an integer n > 0 is <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/exploring-binary-numbers-with-parigp-calculator/d39e275dcd75dc7f927891c0f784e5a6.png' alt='\mbox{\footnotesize{\displaystyle{\lfloor log_2(n) \rfloor + 1}}}'/>:</p>
<pre>
? <strong>n=2^32-1</strong>
%1 = 4294967295

? <strong>floor(log(n)/log(2))+1</strong>
%2 = 32

? <strong>n=2^32</strong>
%3 = 4294967296

?<strong> floor(log(n)/log(2))+1</strong>
%4 = 33

? <strong>n=100</strong>
%5 = 100

? <strong>floor(log(n)/log(2))+1</strong>
%6 = 7
</pre>
<p>(As mentioned above, for large numbers, be sure to set the precision high enough so that the logarithm gives the correct result.)</p>
<h3><a name="count-one-bits"></a>Count Number of 1 Bits</h3>
<p>The number of 1 bits in the binary representation of an integer n > 0 is computed by checking each bit of the binary representation with the <strong>bittest()</strong> function:</p>
<pre>
? <strong>n=7</strong>
%1 = 7

? <strong>sum(i=1,floor(log(n)/log(2))+1,bittest(n,i-1))</strong>
%2 = 3

? <strong>n=2^32-1</strong>
%3 = 4294967295

? <strong>sum(i=1,floor(log(n)/log(2))+1,bittest(n,i-1))</strong>
%4 = 32

? <strong>n=2^32</strong>
%5 = 4294967296

? <strong>sum(i=1,floor(log(n)/log(2))+1,bittest(n,i-1))</strong>
%6 = 1
</pre>
<p>(As mentioned above, for large numbers, be sure to set the precision high enough so that the logarithm gives the correct result.)</p>
<p>bittest() works on the underlying binary representation of a number. It numbers bits from right to left, starting at bit 0.</p>
<p>Counting the number of 1 bits is another way to check whether an integer is a power of two &#8212; <a href="http://www.exploringbinary.com/ten-ways-to-check-if-an-integer-is-a-power-of-two-in-c/" title="Read Rick Regan's Article &ldquo;Ten Ways to Check if an Integer Is a Power Of Two in C&rdquo;">it is a power of two if it has one, and only one, 1 bit</a>.</p>
<p>You can also compute the distribution of 1 bits for the numbers 0 to 2<sup>n</sup> &#8211; 1 by computing row n of Pascal&#8217;s Triangle. For example, here are the binary representations of the numbers 0 through 7:</p>
<pre>
? <strong>for(i=0,7,print(binary(i)))</strong>
[0]
[1]
[1, 0]
[1, 1]
[1, 0, 0]
[1, 0, 1]
[1, 1, 0]
[1, 1, 1]
</pre>
<p>Here is row 3 of Pascal&#8217;s Triangle:</p>
<pre>
? <strong>n=3</strong>
%1 = 3

? <strong>for(i=0,n,print(binomial(n,i)))</strong>
1
3
3
1
</pre>
<p>This tells us that</p>
<ul>
<li>1 number has 0 1 bits (0)</li>
<li>3 numbers have 1 1 bit (1, 10, 100)</li>
<li>3 numbers have 2 1 bits (11, 101, 110)</li>
<li>1 number has 3 1 bits (111)</li>
</ul>
<h2>Acknowledgements</h2>
<p>Thanks to the <a title="PARI/GP Mailing List" href="http://pari.math.u-bordeaux.fr/archives/">PARI/GP mailing list</a>, especially Kurt Foster, John Cremona, Bill Allombert, and Karim Belabas, for their ideas and for answering my questions.</p>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/">Exploring Binary Numbers With PARI/GP Calculator</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/exploring-binary-numbers-with-parigp-calculator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Powers Of Two In The Josephus Problem</title>
		<link>http://www.exploringbinary.com/powers-of-two-in-the-josephus-problem/</link>
		<comments>http://www.exploringbinary.com/powers-of-two-in-the-josephus-problem/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 19:39:14 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Algebra]]></category>
		<category><![CDATA[Exponents]]></category>
		<category><![CDATA[Proof]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=242</guid>
		<description><![CDATA[Pradeep Mutalik of The New York Times recently blogged about a puzzle that is an instance of the Josephus Problem. The problem, restated simply, is this: there are n people standing in a circle, of which you are one. Someone outside the circle goes around clockwise and repeatedly eliminates every other person in the circle, [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/powers-of-two-in-the-josephus-problem/">Powers Of Two In The Josephus Problem</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a title="Pradeep Mutalik of The New York Times" href="http://tierneylab.blogs.nytimes.com/author/pradeep-mutalik/">Pradeep Mutalik of The New York Times</a> recently blogged about a <a title="New York Times Blog Post About the Josephus Problem - Puzzle" href="http://tierneylab.blogs.nytimes.com/2009/06/15/monday-puzzle-fire-your-boss/">puzzle</a> that is an instance of the <a title="Wikipedia Article About the Josephus Problem" href="http://en.wikipedia.org/wiki/Josephus_problem">Josephus Problem</a>. The problem, restated simply, is this: there are n people standing in a circle, of which you are one. Someone outside the circle goes around clockwise and repeatedly eliminates <em>every other person in the circle</em>, until one person &#8212; the winner &#8212; remains. Where should you stand so you become the winner? </p>
<p>Here&#8217;s an example with 13 participants:</p>
<div class="wp-caption aligncenter" style="width: 243px"><img src="http://www.exploringbinary.com/wp-content/uploads/Josephus13-intro.png" alt="Alternating Elimination with 13 people, order of elimination shown in red (winner is person 11)" width="233" height="235"/><p class="wp-caption-text">Alternating Elimination with 13 people, order of elimination shown in red (winner is person 11)</p></div>
<p>As <a title="New York Times Blog Post About the Josephus Problem - Solution" href="http://tierneylab.blogs.nytimes.com/2009/07/09/solutions-and-prizes-for-the-circle-of-fire-problem/">Pradeep</a> and his <a title="New York Times Blog Post About the Josephus Problem - Reader Comments" href="http://tierneylab.blogs.nytimes.com/2009/06/15/monday-puzzle-fire-your-boss/#comment-151967">readers</a> point out, there&#8217;s no need to work through the elimination process &#8212; a simple formula will give the answer. This formula, you won&#8217;t be surprised to hear, has connections to <a href="http://www.exploringbinary.com/the-powers-of-two/" title="Read Rick Regan's Article &ldquo;The Powers of Two&rdquo;">the powers of two</a> and binary numbers. I will discuss my favorite solution, one based on the powers of two.</p>
<p><span id="more-242"></span></p>
<h2>When the Number of Participants is a Power of Two</h2>
<p>Alternating elimination means one of every two participants is eliminated. This is halving, and suggests powers of two are involved. Let&#8217;s first explore this with the special case where the number of participants is a power of two, since <a title="Read Rick Regan's Article “How to Check If a Number Is a Power Of Two”" href="http://www.exploringbinary.com/how-to-check-if-a-number-is-a-power-of-two/">powers of two halve neatly into powers of two.</a></p>
<p>Here is an example circle with eight people:</p>
<div class="wp-caption aligncenter" style="width: 497px"><img src="http://www.exploringbinary.com/wp-content/uploads/Josephus8.png" alt="Alternating Elimination (8 people)" width="487" height="832"/><p class="wp-caption-text">Alternating Elimination (8 people)</p></div>
<p>The elimination process works like this: the first pass starts at person 1 and proceeds clockwise, and each new pass starts every time person 1 is reached. The people eliminated on a pass are crossed out, and are marked to indicate the order in which they were eliminated. Eliminated people are then omitted in subsequent diagrams. </p>
<p>Three passes are required to determine the winner:</p>
<ul>
<li>Pass 1 eliminates four people: 2, 4, 6, 8.</li>
<li>Pass 2 eliminates two people: 3, 7.</li>
<li>Pass 3 eliminates one person: 5.</li>
</ul>
<p>This leaves person 1 the winner.</p>
<p>The number of people eliminated (and equivalently, remaining) per pass follows the same pattern as in a <a title="Read Rick Regan's Article “Elements of Binary in the NCAA Basketball Tournament”" href="http://www.exploringbinary.com/elements-of-binary-in-the-ncaa-basketball-tournament/">single-elimination tournament with a power of two number of participants</a>.</p>
<h3>Analysis</h3>
<p>Regardless of the number of participants n, person 1 survives the first pass. Since n is even, as every <a title="Read Rick Regan's Article “A Table of Nonnegative Powers of Two” (positive powers of two start at 2)" href="http://www.exploringbinary.com/a-table-of-nonnegative-powers-of-two/">positive power of two</a> is, person 1 survives the second pass as well. In the first pass, the process goes like this: person 1 is skipped, person 2 is eliminated, person 3 is skipped, person 4 is eliminated, &#8230; , person n-1 is skipped, person n is eliminated. The second pass starts by skipping person 1. </p>
<p>As long as the number of participants per pass is even, as it will be for a power of two starting point, the same pattern is followed: person 1 is skipped each time. <strong>Therefore, for any power of two, person 1 always wins</strong>.</p>
<h4>Proof by Induction</h4>
<p>You can also show that person 1 is the winner using an inductive proof (for details see <a title="Miguel Lerma's Proof of The Josephus Problem" href="http://www.math.northwestern.edu/~mlerma/problem_solving/solutions/josephus.pdf">Miguel Lerma&#8217;s proof of the Josephus problem</a>). Compared to the argument above, induction works in the opposite direction; that is, it builds up to a more complicated problem from a simpler one.</p>
<p>For n = 2<sup>1</sup> = 2 participants, the base case, it&#8217;s easy to see that person 1 is the winner. For the induction hypothesis, assume person 1 is the winner for n = 2<sup>m</sup>. Show person 1 is the winner for n = 2<sup>m+1</sup>.</p>
<p>When n = 2<sup>m+1</sup>, 2<sup>m</sup> people &#8212; all the even numbered people &#8212; are eliminated in the first pass, leaving 2<sup>m</sup> people &#8212; all the odd numbered people &#8212; remaining. By the induction hypothesis, person 1 is the winner of the n = 2<sup>m</sup> remaining people, and thus the winner among all n = 2<sup>m+1</sup> people. Therefore, for any power of two, person 1 always wins.</p>
<h2>When the Number of Participants is NOT a Power of Two</h2>
<p>When the number of participants is <em>not</em> a power of two, we know this much: person 1 can&#8217;t be the winner. This is because at least one pass will have an odd number of participants. Once the first odd participant pass is complete, person 1 will be eliminated at the start of the next pass. </p>
<p>So is there an easy way to determine who <em>is</em> the winner? Let&#8217;s step back and take a closer look at the elimination process in the 13-person example:</p>
<div class="wp-caption aligncenter" style="width: 531px"><img src="http://www.exploringbinary.com/wp-content/uploads/Josephus13.png" alt="Alternating Elimination (13 people)" width="521" height="855"/><p class="wp-caption-text">Alternating Elimination (13 people)</p></div>
<p>Four passes are required to determine the winner:</p>
<ul>
<li>Pass 1 eliminates six people: 2, 4, 6, 8, 10, 12.</li>
<li>Pass 2 eliminates four people: 1, 5, 9, 13.</li>
<li>Pass 3 eliminates one person: 7.</li>
<li>Pass 4 eliminates one person: 3.</li>
</ul>
<p>This leaves person 11 the winner.</p>
<h3>Analysis</h3>
<p>Powers of two come into play here, but you have to change your perspective to see them. They don&#8217;t occur on pass boundaries &#8212; they span them. At some point, during pass 1, the number of participants remaining becomes a power of two. In this example, that occurs when 5 of the 13 people are eliminated, leaving an 8 person problem: 11, 12, 13, 1, 3, 5, 7, 9. This means person 11, <strong>the first person in the new power of two circle, wins</strong>.</p>
<p>Here&#8217;s the 13-person example again, with the 8-person power of two sub case shown explicitly with passes realigned:</p>
<div class="wp-caption aligncenter" style="width: 558px"><img src="http://www.exploringbinary.com/wp-content/uploads/Josephus13-PO2.png" alt="8-Person Power of 2 Subset of 13-Person Problem" width="548" height="1037"/><p class="wp-caption-text">8-Person Power of Two Subset of 13-Person Problem</p></div>
<p>(It occurred to me that the alternating elimination process is an indirect way to check whether a number is a positive power of two. <a title="Read Rick Regan's Article “How to Check If a Number Is a Power Of Two”" href="http://www.exploringbinary.com/how-to-check-if-a-number-is-a-power-of-two/">A number is a positive power of two if and only if, when halved repeatedly, becomes 1</a>.)</p>
<h2>The Equations</h2>
<p>We can solve both cases &#8212; in other words, for an arbitrary number of participants &#8212; using a little math.</p>
<p>Write n as <strong>n = 2<sup>m</sup> + k</strong>, where 2<sup>m</sup> is the largest power of two less than or equal to n. k people need to be eliminated to reduce the problem to a power of two, which means 2k people must be passed over. The next person in the circle, person 2k + 1, will be the winner. In other words, the winner w is <strong>w = 2k + 1</strong>.</p>
<p>Let&#8217;s apply these equations to a few examples:</p>
<ul>
<li><strong>n = 8</strong>: The equations still apply, although using them is unnecessary: n = 8 + 0, so k = 0 and w = 0 + 1 = <strong>1</strong>.</li>
<li><strong>n = 13</strong>: n = 8 + 5, so k = 5 and w = 2*5 + 1 = <strong>11</strong>.</li>
<li><strong>n = 1000</strong>: This is the example in the <a title="New York Times Blog Post About the Josephus Problem - Solution" href="http://tierneylab.blogs.nytimes.com/2009/07/09/solutions-and-prizes-for-the-circle-of-fire-problem/">New York Times</a>: n = 1000 = 512 + 488, so k = 488 and w = 2*488 + 1 = <strong>977</strong>.</li>
</ul>
<h2>The Formula</h2>
<p>We can combine the equations n = 2<sup>m</sup> + k and w = 2k + 1 to get a single formula for w:</p>
<ul>
<li>Rearrange n = 2<sup>m</sup> + k to isolate k: k = n &#8211; 2<sup>m</sup>.</li>
<li>Substitute this expression for k into w = 2k + 1:
<p class="highlighted">w = 2(n &#8211; 2<sup>m</sup>) + 1</p>
</li>
</ul>
<h2>The Formula as a Function of One Variable</h2>
<p>As written, the formula is a function of two variables, n and m. This works fine, but ideally it should be a function of only <em>one</em> variable &#8212; n. This means we have to eliminate m, or more precisely, make m itself a function of n.</p>
<p>We described 2<sup>m</sup> loosely as &#8220;the largest power of two less than or equal to n,&#8221; but that is an algorithmic description. Described mathematically, m is the integer part of the base 2 logarithm of n; that is, m = floor(log<sub>2</sub>(n)), or <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/powers-of-two-in-the-josephus-problem/ca64f5e15b4a4594171a07bca63aa25c.png' alt='\mbox{\footnotesize{\displaystyle{\lfloor log_2(n) \rfloor}}}'/>.</p>
<p>So now we have a formula in terms of the number of participants n:</p>
<p class="highlighted"><img class='align_baseline' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/powers-of-two-in-the-josephus-problem/fbbea7cd3debbe03981c4db678c8f52e.png' alt='\mbox{\footnotesize{\displaystyle{w = 2\left(n $-$ 2^{\lfloor log_2(n) \rfloor} \right) + 1}}}'/></p>
<h2>Summary</h2>
<p>An alternating elimination Josephus problem has a deep connection to the powers of two, a connection reflected in the formula we derived to find the winning spot. The formula requires a few simple calculations, and is a function of the number of participants n: find the largest power of two in n, subtract it from n, double the result, and add 1. The person in that spot will be the winner.</p>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/powers-of-two-in-the-josephus-problem/">Powers Of Two In The Josephus Problem</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/powers-of-two-in-the-josephus-problem/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Elements of Binary in the NCAA Basketball Tournament</title>
		<link>http://www.exploringbinary.com/elements-of-binary-in-the-ncaa-basketball-tournament/</link>
		<comments>http://www.exploringbinary.com/elements-of-binary-in-the-ncaa-basketball-tournament/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 14:33:38 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Exponents]]></category>
		<category><![CDATA[Geometric series]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=223</guid>
		<description><![CDATA[If you&#8217;re a sports fan, you think of basketball when you see this: If you&#8217;re like me, you also think of powers of two, binary trees, logarithms, laws of exponents, geometric sequences, geometric series, and Bernoulli trials &#8212; in short, the elements of binary numbers, binary code, and binary logic. I hope you&#8217;re thinking: &#8220;wow [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/elements-of-binary-in-the-ncaa-basketball-tournament/">Elements of Binary in the NCAA Basketball Tournament</a></p>
]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a sports fan, you think of basketball when you see this:</p>
<div class="wp-caption aligncenter" style="width: 510px"><img src="http://www.exploringbinary.com/wp-content/uploads/NCAA.Basketball.Brackets.jpg" alt="Diagram of the NCAA Basketball Tournament" width="500" height="429"/><p class="wp-caption-text">Basketball or Binary?</p></div>
<p>If you&#8217;re like me, you also think of powers of two, binary trees, logarithms, laws of exponents, geometric sequences, geometric series, and Bernoulli trials &#8212; in short, the elements of binary numbers, binary code, and binary logic.</p>
<p>I hope you&#8217;re thinking: &ldquo;wow &#8212; all that math stuff I hated actually has a practical use!&rdquo;</p>
<p><span id="more-223"></span><br />
<em>(As of 2011, the format of the tournament has changed. Four play-in games, known as the &ldquo;First Four,&rdquo; determine the last four entrants to the 64-team field. My description below applies to the six-round, 64-team part of the tournament, although the NCAA has renumbered the rounds &#8212; the old first round is now the second round, etc.) </em></p>
<h2>Powers of Two</h2>
<p>The NCAA Basketball Tournament, depicted in the diagram above, is a 64-team, single-elimination tournament. Why 64 teams? Because 64 is a power of two. <a title="Read Rick Regan's Article &ldquo;How to Check If a Number Is a Power Of Two&rdquo;" href="http://www.exploringbinary.com/how-to-check-if-a-number-is-a-power-of-two/">Powers of two halve into powers of two</a>, which gives the tournament symmetry: all 64 teams play in the first round, and teams that meet in rounds thereafter have won the same number of games.</p>
<p><a href="http://www.exploringbinary.com/the-powers-of-two/" title="Read Rick Regan's Article &ldquo;The Powers of Two&rdquo;">Powers of two</a> that pop up in the tournament are: the <a title="Read Rick Regan's Article &ldquo;A Table of Nonnegative Powers of Two&rdquo;" href="http://www.exploringbinary.com/a-table-of-nonnegative-powers-of-two/">nonnegative powers of two</a> 1, 2, 4, 8, 16, 32, 64, and 2<sup>63</sup>, and the <a title="Read Rick Regan's Article &ldquo;A Table of Negative Powers of Two&rdquo;" href="http://www.exploringbinary.com/a-table-of-negative-powers-of-two/">negative powers of two</a> 1/2, 1/4, 1/8, 1/16, 1/32, 1/64, and 1/2<sup>63</sup>.</p>
<h2>Binary Trees</h2>
<p>A <strong>binary tree</strong> is a model of things that have binary structure. The tournament has binary structure because its games are binary; each has one of two outcomes. You can see binary trees in the brackets. Although they are laid out as four separate trees, they are actually part of one big binary tree. This diagram connects them:</p>
<div class="wp-caption aligncenter" style="width: 244px"><img src="http://www.exploringbinary.com/wp-content/uploads/NCAA.Basketball.Brackets64.jpg" alt="Bracketless Representation of the NCAA Basketball Tournament" width="234" height="600"/><p class="wp-caption-text">Bracketless Representation of the NCAA Basketball Tournament.</p></div>
<p>You can see the nested structure in the tree. It is made up of subtrees, each of which is effectively a power of two sized sub-tournament. One 64-team tournament is comprised of two 32-team sub-tournaments, each of which is comprised of two 16-team sub-tournaments, etc. This symmetry, due to the initial power of two number of teams, makes the tree a <a title="Wikipedia article on binary trees" href="http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees">perfect binary tree</a>.</p>
<p>A computer scientist would draw the tree like this:</p>
<div class="wp-caption aligncenter" style="width: 535px"><a href="http://www.exploringbinary.com/wp-content/uploads/BinaryTree64.jpg" title="Click to see full-size image of Binary Tree"><img src="http://www.exploringbinary.com/wp-content/uploads/BinaryTree64-Thumbnail.jpg" alt="The NCAA Tournament Represented As a Binary Tree" width="525" height="248"/></a><p class="wp-caption-text">The NCAA Tournament Represented As a Binary Tree (click for higher resolution).</p></div>
<p>Each circle, called a node, represents a team. The 64 nodes at the bottom, called leaf nodes, represent the 64 teams selected. The 63 nodes above that, called internal nodes, represent teams that have won one or more games. The 63 internal nodes correspond to the 63 games played in the tournament. Each level of internal nodes represents winners of one round. Winners advance up the tree until one team remains at the top node, called the root node. </p>
<p>The internal nodes are labeled by level, from round 1 to round 6. These represent the status of the tournament <em>after</em> the given round is complete. I&#8217;ve labeled the leaf nodes round 0, but they don&#8217;t really represent a round; the 64 teams get there by selection. Round 6 marks the end of the tournament &#8212; the lone team remaining has won all 6 of its games.</p>
<h2>Logarithms</h2>
<p>A logarithm is a fancy word for power, or exponent. You&#8217;re probably familiar with logarithms in base 10, but you can compute logarithms in any base. Logarithms in base 2 are useful when dealing with powers of two. The logarithm in base 2 of a power of two is the exponent corresponding to that power of two. For example, the logarithm in base 2 of 64, or log<sub>2</sub>(64), is 6, which means 64 is 2<sup>6</sup>. In other words, it takes 6 rounds to halve 64 teams down to 1.</p>
<h2>Laws of Exponents</h2>
<p>You can use the <a title="Read Rick Regan's Article &ldquo;Composing Powers of Two Using The Laws of Exponents&rdquo;" href="http://www.exploringbinary.com/composing-powers-of-two-using-the-laws-of-exponents/">laws of exponents</a> to determine how many games are played in any round <em>k</em>:</p>
<p class="center"><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/elements-of-binary-in-the-ncaa-basketball-tournament/74949330519e64f5326dc32ba6a6d7f2.png' alt='\mbox{\footnotesize{\displaystyle{\frac{2^6}{2^k} = 2^{(6-k)}}}}'/></p>
<p>That is a compact way of expressing the halving of 64 teams k times.</p>
<p>Applying the formula, 2<sup>(6-3)</sup> = 2<sup>3</sup> = 8 games are played in round 3. How many games are played in round 6? That&#8217;s easy: 2<sup>(6-6)</sup> = 2<sup>0</sup> = 1.</p>
<h2>Geometric Sequences</h2>
<p>A <strong>geometric sequence</strong>, also known as a geometric progression, is a sequence of numbers that are related by a constant multiple, like sequences of <a href="http://www.exploringbinary.com/the-powers-of-two/" title="Read Rick Regan's Article &ldquo;The Powers of Two&rdquo;">powers of two</a>. In sequences of powers of two, the multiple is either 2 or 1/2. For example, in the sequence 1, 2, 4, 8, 16, 32, 64, each number is double the previous; in the sequence 64, 32, 16, 8, 4, 2, 1, each number is half the previous.</p>
<p>Here are sequences of powers of two that arise in the tournament:</p>
<ul>
<li><strong>64, 32, 16, 8, 4, 2</strong>. The number of teams that play, by round.</li>
<li><strong>32, 16, 8, 4, 2, 1</strong>. The number of games played, by round. Equivalently, it&#8217;s the number of winning teams per round, or the number of losing teams per round.</li>
<li><strong>1/2, 1/4, 1/8, 1/16, 1/32, 1/64</strong>. The fraction of teams that remain, by round.</li>
</ul>
<h2>Geometric Series</h2>
<p>A <em>series</em> is a sum, and a <strong>geometric series</strong> is a sum of numbers from a geometric sequence. The total number of games played in the tournament is a geometric series: 32 + 16 + 8 + 4 + 2 + 1 = 63. Writing it in reverse order &#8212; 1 + 2 + 4 + 8 + 16 + 32 = 63 &#8212; makes it clearer that this notational shortcut applies: </p>
<p class="center"><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/elements-of-binary-in-the-ncaa-basketball-tournament/689d4cf081539db649156c8159f6cb25.png' alt='\mbox{\footnotesize{\displaystyle{\sum_{i=0}^{5}2^i = 63}}}'/></p>
<p>The <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/elements-of-binary-in-the-ncaa-basketball-tournament/816b8fb6e7b0190466c7eec803d34e48.png' alt='\mbox{\footnotesize{\sum}}}'/> symbol means <em>sum</em>, and the way you read it is <em><strong>the sum from i = 0 to 5 of 2<sup>i</sup> is 63</strong></em>. In other words, the sum of the first 6 <a title="Read Rick Regan's Article &ldquo;A Table of Nonnegative Powers of Two&rdquo;" href="http://www.exploringbinary.com/a-table-of-nonnegative-powers-of-two/">nonnegative powers of two</a> is 63.</p>
<p>There is a nice formula that gives the sum without any adding:</p>
<p class="center"><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/elements-of-binary-in-the-ncaa-basketball-tournament/e60045866687dbf707a1f9125bb98fd6.png' alt='\mbox{\footnotesize{\displaystyle{\sum_{i=0}^{n}2^i = 2^{n+1} $-$ 1}}}'/></p>
<p>It says the sum of the first n+1 nonnegative powers of two is one less than the n+2nd nonnegative power of two. For us, n is 5, so the sum is 2<sup>6</sup> &#8211; 1, or 63.</p>
<p>(There&#8217;s another &#8212; some say simpler &#8212; way to count the number of games. Since there are 64 teams, and all but one team loses exactly one game, there must be 63 games. It works, but I find the geometric series explanation more satisfying.)</p>
<p>The formula might be overkill for a basketball tournament, but it comes in handy in other contexts. What&#8217;s the largest value that can fit in a 32-bit binary number? The largest value is represented in binary as 32 1 bits, which represents the first 32 nonnegative powers of two. Applying the formula, we know the sum is 2<sup>32</sup> &#8211; 1, or 4,294,967,295.</p>
<h3>Games Played Through Round k</h3>
<p>There&#8217;s a more general formula to compute the number of games played through <em>any</em> round, not just the last. Doing it by hand, you&#8217;ll see that the total number of games played through each of the 6 rounds is 32, 48, 56, 60, 62, and 63, respectively. That&#8217;s 32, 32 + 16, 32 + 16 + 8, 32 + 16 + 8 + 4, 32 + 16 + 8 + 4 + 2, and 32 + 16 + 8 + 4 + 2 + 1. Except for the last one, those series don&#8217;t start at 1, so the summation formula above does not apply.</p>
<p>That gives me a good excuse to introduce series of negative powers of two. Look at the sum 32 + 16, for instance. That&#8217;s equal to 64 * (1/2 + 1/4). The sum 32 + 16 + 8 + 4 is equal to 64 * (1/2 + 1/4 + 1/8 + 1/16). Those sums all include a series of negative powers of two starting at 2<sup>-1</sup>, and conveniently, there&#8217;s a formula for them:</p>
<p class="center"><img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/elements-of-binary-in-the-ncaa-basketball-tournament/c56a6acb18c0ba8cf3cdcf5dd8e5b6be.png' alt='\mbox{\footnotesize{\displaystyle{\sum_{i=1}^{k} 2^{-i} = \frac{2^{k}-1}{2^{k}}}}}'/></p>
<p>(For those of you that care for such things, that represents the value of a binary fraction consisting of k 1s following the radix point &#8212; but I digress.)</p>
<p>To use that formula, just plug in your value for round k and then multiply by 64, the original number of teams. For example, the number of games played through round 3 is 64 * (2<sup>3</sup> &#8211; 1)/2<sup>3</sup>, or 64 * (7/8), or 56.</p>
<h2>Bernoulli Trials, Outcomes, and Probability</h2>
<p>A <strong>Bernoulli trial</strong> is an event that has one of two possible random outcomes &#8212; flipping a coin is a good example. Each game can be considered a Bernoulli trial; either team A wins or team B wins. From that you can derive the number of different outcomes for the entire tournament. That is, the number of ways the brackets can be filled out: 9,223,372,036,854,775,808.</p>
<p>That&#8217;s nine quintillion, two hundred twenty-three quadrillion, three hundred seventy-two trillion, thirty-six billion, eight hundred fifty-four million, seven hundred seventy-five thousand, eight hundred and eight. Or, if you prefer, 2<sup>63</sup>.</p>
<p>That&#8217;s a big number, but it&#8217;s arrived at fairly simply. One way is to notice that there are 63 games with two outcomes each. By the rules of counting, that&#8217;s 2<sup>63</sup>. But there&#8217;s a longer explanation, one I find more intuitive, and it&#8217;s based on the number of outcomes per round.</p>
<p>There are 2<sup>32</sup> outcomes in round 1, since there are 32 games; there are 2<sup>16</sup> outcomes in round 2, since there are 16 games; etc. But those outcomes are based on only one selection of teams entering that round; you must account for all possible selections. You do that by multiplying. For example, for each of the 2<sup>32</sup> round 1 outcomes, there are 2<sup>16</sup> round 2 outcomes. This means there are 2<sup>32</sup> * 2<sup>16</sup> =  2<sup>(32+16)</sup> = 2<sup>48</sup> outcomes (by the <a title="Read Rick Regan's Article &ldquo;Composing Powers of Two Using The Laws of Exponents&rdquo;" href="http://www.exploringbinary.com/composing-powers-of-two-using-the-laws-of-exponents/">laws of exponents</a>) through round 2. Putting all 6 rounds together, you get:</p>
<p class="center">2<sup>32</sup> * 2<sup>16</sup> * 2<sup>8</sup> * 2<sup>4</sup> * 2<sup>2</sup> * 2<sup>1</sup> = 2<sup>(32+16+8+4+2+1)</sup> = 2<sup>63</sup> .</p>
<p>(I resisted putting a summation symbol in the exponent <img src='http://www.exploringbinary.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .)</p>
<h3>The Office Pool</h3>
<p>If you&#8217;re filling in brackets for your office pool, your odds of guessing all outcomes correctly, in theory, are <strong>1 in 2<sup>63</sup></strong>. In reality, your odds are much better than that, because not all teams are evenly matched.</p>
<p>How about the odds of picking just the winner of the tournament? Those are about 18 orders of magnitude better, at 1 in 64. Again, that&#8217;s theoretical, since it assumes all teams are evenly matched.</p>
<p>What if the lowest numbered seeds were guaranteed to win all their games? Well, it wouldn&#8217;t be much of a tournament, because you might as well skip the first four rounds. The four number one seeds would face each other in the final four, and at that point you&#8217;d have a 1 in 4 chance of picking the winner, and a 1 in 8 chance of filling out the brackets correctly (4 round 5 outcomes multiplied by 2 round 6 outcomes).</p>
<h2>Application to Other Tournaments</h2>
<p>The analysis above applies directly to other 64-competitor tournaments, like the World Golf Championship match play tournament and the Wimbledon doubles tennis tournaments. The analysis also generalizes to other power of two sized tournaments, like the NCAA National Invitational Tournament (32 teams, 31 games, and 5 rounds) and the Wimbledon singles tennis tournaments (128 players, 127 matches, and 7 rounds).</p>
<p>(Caution: just because a tournament starts with a power of two number of competitors doesn&#8217;t mean it has to be laid out symmetrically. For example, in the 16-team Big East tournament, there are two rounds of byes before it becomes a symmetric, 8-team tournament.)</p>
<p>Elements of the above analysis apply to many other single-elimination tournaments, even when they don&#8217;t start with a power of two number of competitors. The Big Ten Conference Men&#8217;s Basketball Tournament, for example, starts with eleven teams; it becomes a symmetric 8-team, 7 game, 3 round tournament after the first round.</p>
<p>Elements of the above analysis also apply to other tournament formats, like the winner&#8217;s bracket in <a title="Wikipedia article on double-elimination tournaments" href="http://en.wikipedia.org/wiki/Double-elimination">double-elimination tournaments</a>, and the upper bracket in triple-elimination tournaments.</p>
<p>Tournaments in just about every sport have elements of binary.</p>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/elements-of-binary-in-the-ncaa-basketball-tournament/">Elements of Binary in the NCAA Basketball Tournament</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/elements-of-binary-in-the-ncaa-basketball-tournament/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Powers of Two</title>
		<link>http://www.exploringbinary.com/the-powers-of-two/</link>
		<comments>http://www.exploringbinary.com/the-powers-of-two/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 21:55:54 +0000</pubDate>
		<dc:creator>Rick Regan</dc:creator>
				<category><![CDATA[Powers of two]]></category>
		<category><![CDATA[Decimals]]></category>
		<category><![CDATA[Exponents]]></category>
		<category><![CDATA[Fractions]]></category>

		<guid isPermaLink="false">http://www.exploringbinary.com/?p=148</guid>
		<description><![CDATA[The following infinite set of numbers is known as the powers of two: . Why are they called powers of two? What is the pattern you see? How is the set described mathematically? What are the set&#8217;s components? We will answer those questions in this article. Let&#8217;s start by naming its three basic components, or [...]<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/the-powers-of-two/">The Powers of Two</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The following infinite set of numbers is known as <strong><em>the powers of two</em></strong>:</p>
<p class="center"><img class='align_baseline' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/the-powers-of-two/f3c03189e0917fca5f94673a9d52dff7.png' alt='\mbox{\footnotesize{\left\{ {\ldots, \frac{1}{64}, \frac{1}{32}, \frac{1}{16}, \frac{1}{8}, \frac{1}{4}, \frac{1}{2}, 1, 2, 4, 8, 16, 32, 64, \ldots} \right\}}}'/>.</p>
<p>Why are they called powers of two? What is the pattern you see? How is the set described mathematically? What are the set&#8217;s components? We will answer those questions in this article.</p>
<p><span id="more-148"></span>Let&#8217;s start by naming its three basic components, or subsets: <strong><em>the positive powers of two</em></strong>, <strong><em>the negative powers of two</em></strong>, and <strong><em>two to the zeroth power</em></strong>. These will serve as a guide through our explanation.</p>
<h2>The Positive Powers of Two</h2>
<p>Consider the set of numbers you get when you start with the number two and keep doubling: {2, 4, 8, 16, 32, 64, &#8230;}. This is the infinite set of positive integers known as <strong><em>the positive powers of two</em></strong>.</p>
<p>Why are numbers in this set called positive powers of two?  First, what is a &#8220;positive power&#8221;?  A positive power is another term for &#8220;positive exponent,&#8221; which is just shorthand for multiplication. Instead of 2&middot;2&middot;2&middot;2&middot;2, for example, you could write 2<sup>5</sup>.  This reads &#8220;two raised to the fifth power&#8221; or &#8220;two to the fifth power&#8221; or simply &#8220;two to the fifth.&#8221; However you choose to say it, it means five twos multiplied together &#8212; 32.  Since it is two we are raising to the power, we call 2<sup>5</sup> a power of two; and more specifically in this case, a positive power of two.</p>
<p>In the order in which we&#8217;ve listed them, each positive power of two is two times the previous.  You can show the factors of two explicitly by writing</p>
<p class="center">{2, 2&middot;2, 2&middot;2&middot;2, 2&middot;2&middot;2&middot;2, 2&middot;2&middot;2&middot;2&middot;2, 2&middot;2&middot;2&middot;2&middot;2&middot;2, &#8230;}.</p>
<p>Using exponents, you can rewrite it as {2<sup>1</sup>, 2<sup>2</sup>, 2<sup>3</sup>, 2<sup>4</sup>, 2<sup>5</sup>, 2<sup>6</sup>, &#8230;}. (Recall that 2<sup>1</sup> simply means 2 &#8212; no multiplication is involved.) Recognizing the pattern, we can write it more concisely as <strong>{2<sup>n</sup> &#124; n is an integer &gt; 0}</strong>, which reads &#8220;the set of all elements 2<sup>n</sup> such that n is a positive integer.&#8221; </p>
<h2>The Negative Powers of Two</h2>
<p>Consider the set of numbers you get when you start with the fraction 1/2 and keep halving: <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/the-powers-of-two/6f0132ecbc59e104bbbd82ba73709229.png' alt='\mbox{\footnotesize{\left\{ {\frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \frac{1}{16}, \frac{1}{32}, \frac{1}{64}, \ldots} \right\}}}'/>. Equivalently, consider the set of numbers you get when you start with the decimal fraction 0.5 and keep halving: {0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625, &#8230;}. In either form, this is the infinite set of positive fractions known as <strong><em>the negative powers of two</em></strong>.</p>
<p>Why are numbers in this set called negative powers of two?  Well first of all, what is a <em>negative</em> power, or negative exponent? Surely it isn&#8217;t shorthand for multiplying a negative number of factors &#8212; that wouldn&#8217;t make sense. Then what, for example, does 2<sup>-5</sup> (two to the negative fifth or two to the minus fifth) mean?  It means raise two to the fifth power and then <em>invert</em> it, giving 1/2<sup>5</sup> = 1/32 = 0.03125. This inverse relationship is clear when you compare the sets {2, 4, 8, 16, 32, 64, &#8230;} and <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/the-powers-of-two/6f0132ecbc59e104bbbd82ba73709229.png' alt='\mbox{\footnotesize{\left\{ {\frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \frac{1}{16}, \frac{1}{32}, \frac{1}{64}, \ldots} \right\}}}'/>.</p>
<p>In the order in which we&#8217;ve listed them, each negative power of two is one-half the previous. You can show the factors of one-half explicitly by writing</p>
<p class="center"><img class='align_baseline' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/the-powers-of-two/da53f178fc34495420d1930ddbb6bdd2.png' alt='\mbox{\footnotesize{\left\{ {\frac{1}{2}, \, \frac{1}{2} {\cdot} \frac{1}{2}, \, \frac{1}{2} {\cdot} \frac{1}{2} {\cdot} \frac{1}{2}, \, \frac{1}{2} {\cdot} \frac{1}{2} {\cdot} \frac{1}{2} {\cdot} \frac{1}{2}, \, \frac{1}{2} {\cdot} \frac{1}{2} {\cdot} \frac{1}{2} {\cdot} \frac{1}{2} {\cdot} \frac{1}{2}, \, \frac{1}{2} {\cdot} \frac{1}{2} {\cdot} \frac{1}{2} {\cdot} \frac{1}{2} {\cdot} \frac{1}{2} {\cdot} \frac{1}{2}, \, \ldots} \right\}}}'/>.</p>
<p>If you combine the denominators you get</p>
<p class="center"><img class='align_baseline' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/the-powers-of-two/3129ed60141874add03da1ec9399f513.png' alt='\mbox{\footnotesize{\left\{ {\frac{1}{2}, \, \frac{1}{2 \cdot 2}, \, \frac{1}{2 \cdot 2 \cdot 2}, \, \frac{1}{2 \cdot 2 \cdot 2 \cdot 2}, \, \frac{1}{2 \cdot 2 \cdot 2 \cdot 2 \cdot 2}, \, \frac{1}{2 \cdot 2 \cdot 2 \cdot 2 \cdot 2 \cdot 2}, \, \ldots} \right\}}}'/>.</p>
<p>This can be expressed using positive exponents as</p>
<p class="center"><img class='align_baseline' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/the-powers-of-two/26161ef54b31ccbb0b42b5f09606ec22.png' alt='\mbox{\footnotesize{\left\{ {\frac{1}{2^1}, \frac{1}{2^2}, \frac{1}{2^3}, \frac{1}{2^4}, \frac{1}{2^5}, \frac{1}{2^6}, \ldots} \right\}}}'/>.</p>
<p>Recognizing these as negative exponents in disguise, you can rewrite it as {2<sup>-1</sup>, 2<sup>-2</sup>, 2<sup>-3</sup>, 2<sup>-4</sup>, 2<sup>-5</sup>, 2<sup>-6</sup>, &#8230;}. Written more concisely, this is <strong>{2<sup>n</sup> &#124; n is an integer &lt; 0}</strong>, which reads &#8220;the set of all elements 2<sup>n</sup> such that n is a negative integer.&#8221;</p>
<p>It&#8217;s worth emphasizing &#8212; the word &#8220;negative&#8221; qualifies the word &#8220;powers&#8221; and not the phrase &#8220;powers of two.&#8221; It is the power that is negative, not the power of two. We wouldn&#8217;t say, for example, that -8 is a negative power of two (although it is in a different sense &#8212; it&#8217;s a power of two that&#8217;s negative). Just remember &#8212; negative powers of two are positive numbers!</p>
<h2>Two to The Zeroth Power</h2>
<p>To this point we&#8217;ve discussed raising two to all integer powers except zero. So what is two to the zeroth power, or 2<sup>0</sup>?  An exponent of zero does not have a neat interpretation like positive or negative exponents. It&#8217;s just <em>defined</em> to be one (so that exponent arithmetic works out). So like any number (except zero) raised to the zeroth power, 2<sup>0</sup> = 1. So one is a power of two, and for our purposes we&#8217;ll refer to it as the one-element set {1} or <strong>{2<sup>0</sup>}</strong>.</p>
<h2>The Powers of Two</h2>
<p>If you combine the positive powers of two, the negative powers of two, and {2<sup>0</sup>} you get the set known collectively as <strong><em>the powers of two</em></strong>. This is the set of all elements 2<sup>n</sup> such that n is an integer, or <strong>{2<sup>n</sup> &#124; n is an integer}</strong>. These are the values </p>
<p class="center"><img class='align_baseline' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/the-powers-of-two/f3c03189e0917fca5f94673a9d52dff7.png' alt='\mbox{\footnotesize{\left\{ {\ldots, \frac{1}{64}, \frac{1}{32}, \frac{1}{16}, \frac{1}{8}, \frac{1}{4}, \frac{1}{2}, 1, 2, 4, 8, 16, 32, 64, \ldots} \right\}}}'/>,</p>
<p> or equivalently, with fractions in decimal form,</p>
<p class="center">{&#8230;, 0.015625, 0.03125, 0.0625, 0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 64, &#8230;}.</p>
<p>You&#8217;ll notice that in this set we&#8217;ve written the negative powers of two in reverse. This is the standard way to display a set that is infinite in &#8220;both directions.&#8221; It corresponds to the orientation of the number line; the numbers get infinitely small as you go left and infinitely large as you go right. Also, it shows a simple relationship when written this way: for any two adjacent numbers, the one to the right is double the one to the left, or equivalently, the one to the left is half the one to the right.</p>
<h2>Other partitions</h2>
<p>It is sometimes convenient to partition the powers of two in other ways.  For example, you can think of the set as being composed of just two subsets: the negative powers of two and <strong><em>the nonnegative powers of two</em></strong>.  The nonnegative powers of two combine {2<sup>0</sup>} and the positive powers of two: {1, 2, 4, 8, 16, 32, 64, &#8230;} or <strong>{2<sup>n</sup> &#124; n is an integer &ge; 0}</strong>.  This breakdown is commonly used in the context of binary numbers, for example.</p>
<p>Similarly, you can think of the powers of two as being composed of the positive powers of two and <strong><em>the nonpositive powers of two</em></strong>. The nonpositive powers of two combine {2<sup>0</sup>} and the negative powers of two, and is written <img class='align_middle' src='http://www.exploringbinary.com/wp-content/uploads/latexrender/pictures/the-powers-of-two/ce0260a98ab411b546e73be30fdaf657.png' alt='\mbox{\footnotesize{\left\{1, {\frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \frac{1}{16}, \frac{1}{32}, \frac{1}{64}, \ldots} \right\}}}'/> or <strong>{2<sup>n</sup> &#124; n is an integer &le; 0}</strong>. This breakdown is not used commonly, however.</p>
<h2>Summary</h2>
<p>The following diagram summarizes what we&#8217;ve discussed:</p>
<div class="wp-caption aligncenter" style="width: 419px"><img class="centered" title="The powers of two and its various subsets." src="http://www.exploringbinary.com/wp-content/uploads/PO2-sets.jpg" alt="The powers of two and its major subsets." width="409" height="215" /><p class="wp-caption-text">The powers of two and its major subsets.</p></div>
<p>Here is the same, in symbols:</p>
<ul>
<li>The powers of two = <strong>{2<sup>n</sup> &#124; n is an integer}</strong>.</li>
<li>The positive powers of two = <strong>{2<sup>n</sup> &#124; n is an integer &gt; 0}</strong>.</li>
<li>The negative powers of two = <strong>{2<sup>n</sup> &#124; n is an integer &lt; 0}</strong>.</li>
<li>The nonnegative powers of two = <strong>{2<sup>n</sup> &#124; n is an integer &ge; 0}</strong>.</li>
<li>The nonpositive powers of two = <strong>{2<sup>n</sup> &#124; n is an integer &le; 0}</strong>.</li>
</ul>
<p>And now the same, in words:</p>
<p>A power of two is the number two raised to an integer power.  A power of two is classified according to the sign of its exponent: positive, negative, nonnegative, or nonpositive.  Powers of two are positive numbers. Nonnegative powers of two are integers, and negative powers of two are fractions. The negative powers of two are just the reciprocals of the positive powers of two, and are expressed as either proper fractions or decimals.</p>
<h2>Endnotes</h2>
<h3>Competing Definitions</h3>
<p>If this definition of the powers of two is broader than one you&#8217;ve seen it&#8217;s because there are other definitions in common use (see <a href="http://www.exploringbinary.com/a-standard-definition-of-the-powers-of-two/" title="Read Rick Regan's Article &ldquo;A Standard Definition of The Powers of Two&rdquo;">&#8220;A Standard Definition of The Powers of Two&#8221;</a>).</p>
<h3>Set vs. Sequence</h3>
<p>Technically, we&#8217;re being loose about the distinction between a set and a sequence. A set describes its elements without specifying order, whereas a sequence describes a particular ordering of elements. {1, 2, 4} and {4, 1, 2} are the same set, but (1, 2, 4) and (4, 1, 2) are different sequences.</p>
<p>We&#8217;ve listed powers of two in a particular order and described properties of that ordering, which means we&#8217;ve implicitly defined a sequence as well &#8212; a geometric sequence in fact. Where this does not cause confusion, we will exploit this fact, as in phrases like &#8220;add the first six nonnegative powers of two.&#8221; </p>
<p>By Rick Regan (Copyright &copy; 2008-2012  <a href="http://www.exploringbinary.com">Exploring Binary</a>)<br/><br/><a href="http://www.exploringbinary.com/the-powers-of-two/">The Powers of Two</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exploringbinary.com/the-powers-of-two/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

