<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet href='http://feed.feedsky.com/styles/temp01.xsl' type='text/xsl' ?><!--这是一个由Feedsy提供技术支持的Feed，为了提高读者阅读的体验，以及满足用户美化自己Feed的需要，我们设计了多种精美的Feed模板，提供给大家选择，所有最终呈现出来的样式，皆由用户自愿选择使用，未经许可，任何团体和个人，请不要擅自修改样式或者盗用，这是对于用户选择权的尊重。--><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:fs="http://www.feedsky.com/namespace/feed" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link href="http://feed.feedsky.com/apzc2529" type="application/rss+xml" rel="self"></atom:link><fs:self_link href="http://feed.feedsky.com/apzc2529" type="application/rss+xml"></fs:self_link><lastBuildDate>Fri, 15 Jan 2010 02:46:05 GMT</lastBuildDate><title>Cun Zhang's Blog</title><description>Math Software,Related</description><image><url>http://www.feedsky.com/images/feedsky_logologo.gif</url><title>Cun Zhang's Blog</title><link>http://blog.4message.net</link></image><link>http://blog.4message.net</link><sy:updatePeriod>hourly</sy:updatePeriod><sy:updateFrequency>1</sy:updateFrequency><language>en</language><pubDate>Fri, 15 Jan 2010 02:46:05 GMT</pubDate><item><title>Prevent xscreensaver from blanking when watching movies</title><link>http://blog.4message.net/2010/01/15/prevent-xscreensaver-from-blanking-when-watching-movies.html</link><content:encoded>&lt;div class=&quot;answer&quot;&gt;&lt;b&gt;&lt;br /&gt;
        How do I prevent xscreensaver from blanking the screen when&lt;br /&gt;
        I&amp;#8217;m watching movies on my computer?&lt;/b&gt;&lt;/div&gt;
&lt;p&gt; If you are using a recent version of&lt;br /&gt;
  &lt;a href=&quot;http://www.mplayerhq.hu/&quot;&gt;MPlayer&lt;/a&gt;, put this&lt;br /&gt;
  in your ~/.mplayer/config file:&lt;/p&gt;
&lt;/p&gt;
&lt;ul&gt;
    heartbeat-cmd=&amp;#8221;xscreensaver-command -deactivate&amp;#8221;
  &lt;/ul&gt;
&lt;p&gt; If you&amp;#8217;re using something other than MPlayer:&lt;/p&gt;
&lt;/p&gt;
&lt;ul&gt;
   When you want to watch a movie, fire up&lt;br /&gt;
  &lt;a href=&quot;http://www.jwz.org/xscreensaver/man2.html&quot;&gt;xscreensaver-demo&lt;/a&gt; and select&lt;br /&gt;
  &lt;b&gt;Mode: Disable Screen Saver&lt;/b&gt; from the option menu, which means&lt;br /&gt;
  not to blank the screen at all.  When you&amp;#8217;re done watching the movie,&lt;br /&gt;
  re-select your previous mode.&lt;/p&gt;
&lt;p&gt; That&amp;#8217;s kind of lame, I know.  You should ask the author of the&lt;br /&gt;
  movie-playing software you are using to add explicit support for&lt;br /&gt;
  xscreensaver to their program.
  &lt;/p&gt;
&lt;/ul&gt;
&lt;p&gt;If you are the author of movie-playing software:&lt;/p&gt;
&lt;ul&gt;
&lt;p&gt;    The way you prevent xscreensaver from blanking the screen&lt;br /&gt;
    while a movie is playing is something like this:&lt;/p&gt;
&lt;p&gt;    &lt;font face=&quot;Courier New&quot;&gt;    if (playing &amp;#038;&amp;#038; !paused) {&lt;br /&gt;      system (&amp;#8221;xscreensaver-command -deactivate &gt;&amp;#038;- 2&gt;&amp;#038;- &amp;#038;&amp;#8221;);&lt;br /&gt;    }&lt;/font&gt;
&lt;p&gt; Though it would be better to code this using fork()&lt;br /&gt;
    and execvp() instead of system().&lt;/p&gt;
&lt;p&gt; That will prevent the screen saver from activating while the&lt;br /&gt;
    movie is playing, but will allow it to activate normally while the&lt;br /&gt;
    movie is stopped or paused.  You probably ought to make this&lt;br /&gt;
    behavior a preference, so that you don&amp;#8217;t permanently deactivate the&lt;br /&gt;
    screen saver when, for example, someone is playing movies in a loop&lt;br /&gt;
    on their root window, or when your player is being used as a web&lt;br /&gt;
    page plugin.&lt;/p&gt;
&lt;p&gt; The reason to do this with a timer (instead of turning the&lt;br /&gt;
    screensaver off and then on again in some other way) is so that if&lt;br /&gt;
    your program crashes, you&amp;#8217;re guaranteed that the screensaver will&lt;br /&gt;
    not be left in a permanently disabled state.&lt;/p&gt;
&lt;p&gt; If you think this is &amp;#8220;too inefficient,&amp;#8221; you&amp;#8217;re mistaken.&lt;br /&gt;
    (You haven&amp;#8217;t actually timed it, have you?  I didn&amp;#8217;t think so.)&lt;/p&gt;
&lt;p&gt; Please also consider adding a command-line option to your&lt;br /&gt;
    movie player to let it play movies in a loop on the root window,&lt;br /&gt;
    with the GUI controls hidden, so that your program can be used to&lt;br /&gt;
    play movies &lt;i&gt;as&lt;/i&gt; a screen saver!&lt;/p&gt;
&lt;/ul&gt;
&lt;p&gt;From: http://www.jwz.org/xscreensaver/faq.html&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/321829749/apzc2529/feedsky/s.gif?r=http://blog.4message.net/2010/01/15/prevent-xscreensaver-from-blanking-when-watching-movies.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829749/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829749/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><wfw:commentRss>http://blog.4message.net/2010/01/15/prevent-xscreensaver-from-blanking-when-watching-movies.html/feed</wfw:commentRss><slash:comments>0</slash:comments><description>How do I prevent xscreensaver from blanking the screen when
        I&amp;#8217;m watching movies on my computer?
 If you are using a recent version of
  MPlayer, put this
  in your ~/.mplayer/config file:


    heartbeat-cmd=&amp;#8221;xscreensaver-command -deactivate&amp;#8221;
  
 [...]&lt;img src=&quot;http://www1.feedsky.com/t1/321829749/apzc2529/feedsky/s.gif?r=http://blog.4message.net/2010/01/15/prevent-xscreensaver-from-blanking-when-watching-movies.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829749/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829749/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><category>Uncategorized</category><pubDate>Fri, 15 Jan 2010 10:46:05 +0800</pubDate><author>Cun Zhang</author><comments>http://blog.4message.net/2010/01/15/prevent-xscreensaver-from-blanking-when-watching-movies.html#comments</comments><guid isPermaLink="false">http://blog.4message.net/2010/01/15/prevent-xscreensaver-from-blanking-when-watching-movies.html</guid><dc:creator>Cun Zhang</dc:creator><fs:srclink>http://blog.4message.net/2010/01/15/prevent-xscreensaver-from-blanking-when-watching-movies.html</fs:srclink><fs:srcfeed>http://blog.4message.net/feed</fs:srcfeed><fs:itemid>feedsky/apzc2529/~7024609/321829749/4784867</fs:itemid></item><item><title>Mathtype Tips</title><link>http://blog.4message.net/2010/01/07/mathtype-tips.html</link><content:encoded>&lt;h4&gt;1 MathType批量修改公式的字号和大小&lt;/h4&gt;
&lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;   在Word中双击一个公式，打开mathtype，进入编辑状态，点击尽尺寸（size）菜单-&gt;定义（define）-&gt;字号对应的pt值，&lt;br /&gt;一般五号对应10.5pt，小四对应12pt。其他可以自己按照具体要求自行调节。其他默认大小设置不推荐改动。然后点击&lt;br /&gt;参数（preference）-&gt;方程参数（equation preference） -&gt;保存到文件（save to file） -&gt;存一个与默认配置文件不同的名字，&lt;br /&gt;然后关闭mathtype回到word文档。点击word界面上的mathtype -&gt;format equation -&gt; load equation preferrence选项&lt;br /&gt;下面的browse按钮，选中刚才存的配置文件，点选whole document选项，确定，就安心等着公式一个个改过来。&lt;/font&gt;&lt;br /&gt;
&lt;h4&gt;2. 利用Mathtype显示LaTeX公式&lt;/h4&gt;
&lt;p&gt;　　有时候我们可能利用Matlab做一些理论推导，推导出的公式可能很复杂，而且非常不直观，经常费很大力气写成直观的数学形式。&lt;br /&gt;这时候有一个比较简便的办法可以达到这个目的，那便是利用Matlab提够的latex命令将其转换为latex格式，然后直接复制进 Mathtype，&lt;br /&gt;就会自动转换为直观的数学形式。&lt;br /&gt;
&lt;h4&gt;3. 充分利用Mathtype的公式自动编号及索引功能&lt;/h4&gt;
&lt;p&gt;　　在论文修改阶段，可能反复删减论文，手动编号就会显得非常繁琐、费时又费力。利用Mathtype能够很方便地实现自动编号。&lt;br /&gt;不过大量公式编号，总是反复点击鼠标也是个问题。这可以利用Word的自定义快捷键来解决。&lt;br /&gt;　　选择&lt;font face=&quot;SimSun,宋体,MS Song,serif&quot;&gt;“工具”—&gt;“自定义”，点击最下面的“键盘”按钮，出来“自定义键盘”对话框，然后在类别下面选择“宏”，&lt;br /&gt;再选择“InsertEqnNum”，点击“请按新快捷键”，这时按下新快捷键&lt;/font&gt;（我设置为了Ctrl+Shift+N），点击&lt;font face=&quot;SimSun,宋体,MS Song,serif&quot;&gt;“设定”，&lt;br /&gt;便会显示在“当前快捷键”里&lt;/font&gt;，点&lt;font face=&quot;SimSun,宋体,MS Song,serif&quot;&gt;“关闭”设定便完成了。&lt;br /&gt;　　如何使用那？在Word里输入完公式，需要插入公式编号，按下快捷键 Ctrl+Shift+N，公式编号便生成了。公式编号发生变化后，&lt;br /&gt;双击某个公式编号，便自动更新了。&lt;br /&gt;　　公式编号样式的定制可以在Word的Mathtype菜单栏里找到，不再详述。&lt;/p&gt;
&lt;p&gt;&lt;/font&gt;&lt;br /&gt;
&lt;h4&gt;&lt;font face=&quot;SimSun,宋体,MS Song,serif&quot;&gt;4. 自定义编号&lt;/font&gt;&lt;/h4&gt;
&lt;p&gt;&lt;font face=&quot;SimSun,宋体,MS Song,serif&quot;&gt;　　今天排版论文遇到一个小问题：使用的是Mathtype的自动编号，其间需要插入一个需要手动编号的公式，比如1-4自动编号，&lt;br /&gt;然后第5个公式手动编号（例如5a,5b,5c），然后再继续编号应该从6开始。由于是自动编号，所以Mathtype自动将(6)编号为了(5)。&lt;br /&gt;google了很久也没有找到答案。后来终于从宏代码中发现了一些端倪，修改宏代码测试终于搞定。&lt;br /&gt;　　具体做法如下：&lt;br /&gt;　　点击公式编号，右键选择“切换域代码”，显示如下：&lt;/font&gt;&lt;br /&gt;{ MACROBUTTON MTPlaceRef * MERGEFORMAT { SEQ MTEqn h * MERGEFORMAT }({ SEQ MTEqn c * Arabic * MERGEFORMAT })}&lt;/p&gt;
&lt;p&gt;修改为下面的代码：&lt;/p&gt;
&lt;p&gt;{ MACROBUTTON MTPlaceRef * MERGEFORMAT { SEQ MTEqn &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;r 5&lt;/span&gt; h * MERGEFORMAT }({ SEQ MTEqn c * Arabic * MERGEFORMAT })}&lt;/p&gt;
&lt;p&gt;然后双击公式编号更新即可。&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/321829750/apzc2529/feedsky/s.gif?r=http://blog.4message.net/2010/01/07/mathtype-tips.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829750/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829750/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><wfw:commentRss>http://blog.4message.net/2010/01/07/mathtype-tips.html/feed</wfw:commentRss><slash:comments>0</slash:comments><description>1 MathType批量修改公式的字号和大小
   在Word中双击一个公式，打开mathtype，进入编辑状态，点击尽尺寸（size）菜单-&gt;定义（define）-&gt;字号对应的pt值，一般五号对应10.5pt，小四对应12pt。其他可以自己按照具体要求自行调节。其他默认大小设置不推荐改动。然后点击参数（preference）-&gt;方程参数（equation preference） -&gt;保存到文件（save to file） -&gt;存一个与默认配置文件不同的名字，然后关闭mathtype回到word文档。点击word界面上的mathtype -&gt;format equation -&gt; load equation preferrence选项下面的browse按钮，选中刚才存的配置文件，点选whole document选项，确定，就安心等着公式一个个改过来。
2. 利用Mathtype显示LaTeX公式
　　有时候我们可能利用Matlab做一些理论推导，推导出的公式可能很复杂，而且非常不直观，经常费很大力气写成直观的数学形式。这时候有一个比较简便的办法可以达到这个目的，那便是利用Matlab提够的latex命令将其转换为latex格式，然后直接复制进 Mathtype，就会自动转换为直观的数学形式。
3. 充分利用Mathtype的公式自动编号及索引功能
　　在论文修改阶段，可能反复删减论文，手动编号就会显得非常繁琐、费时又费力。利用Mathtype能够很方便地实现自动编号。不过大量公式编号，总是反复点击鼠标也是个问题。这可以利用Word的自定义快捷键来解决。　　选择“工具”—&gt;“自定义”，点击最下面的“键盘”按钮，出来“自定义键盘”对话框，然后在类别下面选择“宏”，再选择“InsertEqnNum”，点击“请按新快捷键”，这时按下新快捷键（我设置为了Ctrl+Shift+N），点击“设定”，便会显示在“当前快捷键”里，点“关闭”设定便完成了。　　如何使用那？在Word里输入完公式，需要插入公式编号，按下快捷键 Ctrl+Shift+N，公式编号便生成了。公式编号发生变化后，双击某个公式编号，便自动更新了。　　公式编号样式的定制可以在Word的Mathtype菜单栏里找到，不再详述。

4. 自定义编号
　　今天排版论文遇到一个小问题：使用的是Mathtype的自动编号，其间需要插入一个需要手动编号的公式，比如1-4自动编号，然后第5个公式手动编号（例如5a,5b,5c），然后再继续编号应该从6开始。由于是自动编号，所以Mathtype自动将(6)编号为了(5)。google了很久也没有找到答案。后来终于从宏代码中发现了一些端倪，修改宏代码测试终于搞定。　　具体做法如下：　　点击公式编号，右键选择“切换域代码”，显示如下：{ MACROBUTTON MTPlaceRef * MERGEFORMAT { SEQ MTEqn h * MERGEFORMAT }({ SEQ MTEqn c * Arabic * MERGEFORMAT })}
修改为下面的代码：
{ MACROBUTTON MTPlaceRef * MERGEFORMAT { SEQ MTEqn r 5 h * MERGEFORMAT }({ SEQ MTEqn c [...]&lt;img src=&quot;http://www1.feedsky.com/t1/321829750/apzc2529/feedsky/s.gif?r=http://blog.4message.net/2010/01/07/mathtype-tips.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829750/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829750/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><category>Uncategorized</category><pubDate>Thu, 07 Jan 2010 18:10:02 +0800</pubDate><author>Cun Zhang</author><comments>http://blog.4message.net/2010/01/07/mathtype-tips.html#comments</comments><guid isPermaLink="false">http://blog.4message.net/2010/01/07/mathtype-tips.html</guid><dc:creator>Cun Zhang</dc:creator><fs:srclink>http://blog.4message.net/2010/01/07/mathtype-tips.html</fs:srclink><fs:srcfeed>http://blog.4message.net/feed</fs:srcfeed><fs:itemid>feedsky/apzc2529/~7024609/321829750/4784867</fs:itemid></item><item><title>丰年好大雪</title><link>http://blog.4message.net/2010/01/03/%e4%b8%b0%e5%b9%b4%e5%a5%bd%e5%a4%a7%e9%9b%aa-2.html</link><content:encoded>&lt;p&gt;&lt;font size=&quot;4&quot;&gt;　　在2010年元旦到来的时候，下了这场几十年难遇的瑞雪，足足20多厘米。似乎第一次见这么厚的雪吧。&lt;br /&gt;
在这个吉祥的日子里，我也许下两个愿望，希望早日成真！&lt;br /&gt;
也祝一直在帮助我、关心我、爱好我的朋友们在新的一年里完事顺心，事事如意！&lt;/p&gt;
&lt;p&gt;村长&lt;br /&gt;
2010年1月3日&lt;/font&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/321829754/apzc2529/feedsky/s.gif?r=http://blog.4message.net/2010/01/03/%e4%b8%b0%e5%b9%b4%e5%a5%bd%e5%a4%a7%e9%9b%aa-2.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829754/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829754/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><wfw:commentRss>http://blog.4message.net/2010/01/03/%e4%b8%b0%e5%b9%b4%e5%a5%bd%e5%a4%a7%e9%9b%aa-2.html/feed</wfw:commentRss><slash:comments>0</slash:comments><description>　　在2010年元旦到来的时候，下了这场几十年难遇的瑞雪，足足20多厘米。似乎第一次见这么厚的雪吧。
在这个吉祥的日子里，我也许下两个愿望，希望早日成真！
也祝一直在帮助我、关心我、爱好我的朋友们在新的一年里完事顺心，事事如意！
村长
2010年1月3日&lt;img src=&quot;http://www1.feedsky.com/t1/321829754/apzc2529/feedsky/s.gif?r=http://blog.4message.net/2010/01/03/%e4%b8%b0%e5%b9%b4%e5%a5%bd%e5%a4%a7%e9%9b%aa-2.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829754/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829754/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><category>Uncategorized</category><pubDate>Sun, 03 Jan 2010 22:12:34 +0800</pubDate><author>Cun Zhang</author><comments>http://blog.4message.net/2010/01/03/%e4%b8%b0%e5%b9%b4%e5%a5%bd%e5%a4%a7%e9%9b%aa-2.html#comments</comments><guid isPermaLink="false">http://blog.4message.net/2010/01/03/%e4%b8%b0%e5%b9%b4%e5%a5%bd%e5%a4%a7%e9%9b%aa-2.html</guid><dc:creator>Cun Zhang</dc:creator><fs:srclink>http://blog.4message.net/2010/01/03/%e4%b8%b0%e5%b9%b4%e5%a5%bd%e5%a4%a7%e9%9b%aa-2.html</fs:srclink><fs:srcfeed>http://blog.4message.net/feed</fs:srcfeed><fs:itemid>feedsky/apzc2529/~7024609/321829754/4784867</fs:itemid></item><item><title>PEXPECT: A tool for automating interactive applications</title><link>http://blog.4message.net/2009/09/16/pexpect-a-tool-for-automating-interactive-applications.html</link><content:encoded>&lt;p&gt;&lt;font size=&quot;3&quot;&gt;Pexpect is a Python module for spawning child applications and controlling them automatically. Pexpect can be used for automating interactive applications such as ssh, ftp, passwd, telnet, etc. It can be used to a automate setup scripts for duplicating software package installations on different servers. It can be used for automated software testing. Pexpect is in the spirit of Don Libes&amp;#8217; Expect, but Pexpect is pure Python. Other Expect-like modules for Python require TCL and Expect or require C extensions to be compiled. Pexpect does not use C, Expect, or TCL extensions. It should work on any platform that supports the standard Python pty module. The Pexpect interface focuses on ease of use so&lt;br /&gt;
that simple tasks are easy.&lt;/p&gt;
&lt;p&gt;There are two main interfaces to Pexpect &amp;#8212; the function, &lt;a href=&quot;http://pexpect.sourceforge.net/pexpect.html#-run&quot;&gt;run&lt;/a&gt;() and the class,&lt;a href=&quot;http://pexpect.sourceforge.net/pexpect.html#spawn&quot;&gt;spawn&lt;/a&gt;. You can call the &lt;a href=&quot;http://pexpect.sourceforge.net/pexpect.html#-run&quot;&gt;run&lt;/a&gt;() function to execute a command and return the output. This is a handy replacement for os.system().&lt;br /&gt;
 &lt;br /&gt;
For example::&lt;br /&gt;
 &lt;br /&gt;
    pexpect.&lt;a href=&quot;http://pexpect.sourceforge.net/pexpect.html#-run&quot;&gt;run&lt;/a&gt;(&amp;#8217;ls -la&amp;#8217;)&lt;br /&gt;
 &lt;br /&gt;
The more powerful interface is the &lt;a href=&quot;http://pexpect.sourceforge.net/pexpect.html#spawn&quot;&gt;spawn&lt;/a&gt; class. You can use this to &lt;a href=&quot;http://pexpect.sourceforge.net/pexpect.html#spawn&quot;&gt;spawn&lt;/a&gt; an external child command and then interact with the child by sending lines and expecting responses.&lt;br /&gt;
 &lt;br /&gt;
For example::&lt;br /&gt;
 &lt;br /&gt;
    child = pexpect.&lt;a href=&quot;http://pexpect.sourceforge.net/pexpect.html#spawn&quot;&gt;spawn&lt;/a&gt;(&amp;#8217;scp foo myname@host.example.com:.&amp;#8217;)&lt;br /&gt;
    child.expect (&amp;#8217;Password:&amp;#8217;)&lt;br /&gt;
    child.sendline (mypassword)&lt;br /&gt;
 &lt;br /&gt;
This works even for commands that ask for passwords or other input outside of the normal stdio streams.&lt;/p&gt;
&lt;p&gt;From: http://pexpect.sourceforge.net/pexpect.html&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/321829755/apzc2529/feedsky/s.gif?r=http://blog.4message.net/2009/09/16/pexpect-a-tool-for-automating-interactive-applications.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829755/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829755/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><wfw:commentRss>http://blog.4message.net/2009/09/16/pexpect-a-tool-for-automating-interactive-applications.html/feed</wfw:commentRss><slash:comments>0</slash:comments><description>Pexpect is a Python module for spawning child applications and controlling them automatically. Pexpect can be used for automating interactive applications such as ssh, ftp, passwd, telnet, etc. It can be used to a automate setup scripts for duplicating software package installations on different servers. It can be used for automated software testing. Pexpect is [...]&lt;img src=&quot;http://www1.feedsky.com/t1/321829755/apzc2529/feedsky/s.gif?r=http://blog.4message.net/2009/09/16/pexpect-a-tool-for-automating-interactive-applications.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829755/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829755/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><category>Uncategorized</category><pubDate>Wed, 16 Sep 2009 18:42:16 +0800</pubDate><author>Cun Zhang</author><comments>http://blog.4message.net/2009/09/16/pexpect-a-tool-for-automating-interactive-applications.html#comments</comments><guid isPermaLink="false">http://blog.4message.net/2009/09/16/pexpect-a-tool-for-automating-interactive-applications.html</guid><dc:creator>Cun Zhang</dc:creator><fs:srclink>http://blog.4message.net/2009/09/16/pexpect-a-tool-for-automating-interactive-applications.html</fs:srclink><fs:srcfeed>http://blog.4message.net/feed</fs:srcfeed><fs:itemid>feedsky/apzc2529/~7024609/321829755/4784867</fs:itemid></item><item><title>Google docs publish test</title><link>http://blog.4message.net/2009/09/11/google-docs-publish-test.html</link><content:encoded>&lt;p&gt;Test&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/321829756/apzc2529/feedsky/s.gif?r=http://blog.4message.net/2009/09/11/google-docs-publish-test.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829756/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829756/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><wfw:commentRss>http://blog.4message.net/2009/09/11/google-docs-publish-test.html/feed</wfw:commentRss><slash:comments>0</slash:comments><description>Test&lt;img src=&quot;http://www1.feedsky.com/t1/321829756/apzc2529/feedsky/s.gif?r=http://blog.4message.net/2009/09/11/google-docs-publish-test.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829756/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829756/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><category>Uncategorized</category><pubDate>Fri, 11 Sep 2009 20:31:43 +0800</pubDate><author>Cun Zhang</author><comments>http://blog.4message.net/2009/09/11/google-docs-publish-test.html#comments</comments><guid isPermaLink="false">http://blog.4message.net/2009/09/11/google-docs-publish-test.html</guid><dc:creator>Cun Zhang</dc:creator><fs:srclink>http://blog.4message.net/2009/09/11/google-docs-publish-test.html</fs:srclink><fs:srcfeed>http://blog.4message.net/feed</fs:srcfeed><fs:itemid>feedsky/apzc2529/~7024609/321829756/4784867</fs:itemid></item><item><title>Project Euler 77</title><link>http://blog.4message.net/2009/04/17/project-euler-77.html</link><content:encoded>&lt;p&gt;This proble is similiar to Projet Euler 76.&lt;br /&gt;
The Python program:&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;python&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;''&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;'
a_1*x_1+a_2*x_2+...+a_V*V=N
A=[a_1,a_2,...,a_V]
A=[2,3,5,7,11,...]
'&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;''&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;try&lt;/span&gt;:
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;import&lt;/span&gt; psyco
        psyco.&lt;span style=&quot;color: black;&quot;&gt;full&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;except&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;ImportError&lt;/span&gt;:
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;pass&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;from&lt;/span&gt; euler &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;import&lt;/span&gt; allprime
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;def&lt;/span&gt; P&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;V,N&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;if&lt;/span&gt; N&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt; =&lt;span style=&quot;color: #ff4500;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;or&lt;/span&gt; V==&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;:
                &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;elif&lt;/span&gt; N&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt;V&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;-&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;:
                &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; P&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;V&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;:-&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;,N&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;elif&lt;/span&gt; V==&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #ff4500;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;:
                &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; N/&lt;span style=&quot;color: #ff4500;&quot;&gt;6&lt;/span&gt;+&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;else&lt;/span&gt;:
                &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;P&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;V&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;:-&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;,N-V&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;-&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;x&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;for&lt;/span&gt; x &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;range&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;N/V&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;-&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;+&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
V,N=&lt;span style=&quot;color: #008000;&quot;&gt;sorted&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;allprime&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;keys&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;while&lt;/span&gt; P&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;V,N&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt; 5e3:
        N=N+&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;print&lt;/span&gt; N&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;/pre&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829757/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829757/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><wfw:commentRss>http://blog.4message.net/2009/04/17/project-euler-77.html/feed</wfw:commentRss><slash:comments>1</slash:comments><description>This proble is similiar to Projet Euler 76.
The Python program:

'''
a_1*x_1+a_2*x_2+...+a_V*V=N
A=[a_1,a_2,...,a_V]
A=[2,3,5,7,11,...]
'''
try:
        import psyco
        psyco.full&amp;#40;&amp;#41;
except ImportError:
        pass
from euler import allprime
def P&amp;#40;V,N&amp;#41;:
        if N&amp;#60; =3 or V==&amp;#91;2&amp;#93;:
    [...]&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829757/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829757/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><category>Uncategorized</category><pubDate>Fri, 17 Apr 2009 13:31:06 +0800</pubDate><author>Cun Zhang</author><comments>http://blog.4message.net/2009/04/17/project-euler-77.html#comments</comments><guid isPermaLink="false">http://blog.4message.net/?p=702</guid><dc:creator>Cun Zhang</dc:creator><fs:srclink>http://blog.4message.net/2009/04/17/project-euler-77.html</fs:srclink><fs:srcfeed>http://blog.4message.net/feed</fs:srcfeed><fs:itemid>feedsky/apzc2529/~7024609/321829757/4784867</fs:itemid></item><item><title>Project Euler 76</title><link>http://blog.4message.net/2009/04/17/project-euler-76.html</link><content:encoded>&lt;p&gt;The problem is equivalent to obtain the number of the integer solutions of the diophantine equation a_1*x_1+a_2*x_2+&amp;#8230;+a_V*V=N.&lt;br /&gt;
We define the number of  the integer solutions of this diophantine equation as P（V,N).&lt;br /&gt;
It can be found that P(V,N) can be expressed as a recursive function as the following:&lt;br /&gt;
P(V,N)=P(V-1,N)+P(V-1,N-V)+&amp;#8230;+P(V-1,N-[N/V]*V).&lt;br /&gt;
So This problem can be easily solved by defining this recursive function.&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;python&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;''&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;'
The number of the integer solutions of a_1*x_1+a_2*x_2+...+a_V*V=N
'&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;''&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;try&lt;/span&gt;:
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;import&lt;/span&gt; psyco
        psyco.&lt;span style=&quot;color: black;&quot;&gt;full&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;except&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;ImportError&lt;/span&gt;:
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;pass&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;def&lt;/span&gt; P&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;V,N&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;if&lt;/span&gt; N&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt; =&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;or&lt;/span&gt; V==&lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt;:
                &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; N/&lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt;+&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;elif&lt;/span&gt; V==&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;:
                &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;elif&lt;/span&gt; N&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt;V:
                &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; P&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;N-&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;,N&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;+&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;
        &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;else&lt;/span&gt;:
                &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;P&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;V-&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;,N-V&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;x&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;for&lt;/span&gt; x &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;xrange&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;N/V+&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;print&lt;/span&gt; P&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;99&lt;/span&gt;,&lt;span style=&quot;color: #ff4500;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;/pre&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829759/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829759/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><wfw:commentRss>http://blog.4message.net/2009/04/17/project-euler-76.html/feed</wfw:commentRss><slash:comments>2</slash:comments><description>The problem is equivalent to obtain the number of the integer solutions of the diophantine equation a_1*x_1+a_2*x_2+&amp;#8230;+a_V*V=N.
We define the number of  the integer solutions of this diophantine equation as P（V,N).
It can be found that P(V,N) can be expressed as a recursive function as the following:
P(V,N)=P(V-1,N)+P(V-1,N-V)+&amp;#8230;+P(V-1,N-[N/V]*V).
So This problem can be easily solved by defining this [...]&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829759/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829759/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><category>Uncategorized</category><pubDate>Fri, 17 Apr 2009 13:20:46 +0800</pubDate><author>Cun Zhang</author><comments>http://blog.4message.net/2009/04/17/project-euler-76.html#comments</comments><guid isPermaLink="false">http://blog.4message.net/?p=694</guid><dc:creator>Cun Zhang</dc:creator><fs:srclink>http://blog.4message.net/2009/04/17/project-euler-76.html</fs:srclink><fs:srcfeed>http://blog.4message.net/feed</fs:srcfeed><fs:itemid>feedsky/apzc2529/~7024609/321829759/4784867</fs:itemid></item><item><title>ProjectEuler 80</title><link>http://blog.4message.net/2009/02/20/projecteuler-80.html</link><content:encoded>&lt;p&gt;It is well known that if the square root of a natural number is not an integer, then it is irrational. The decimal expansion of such square roots is infinite without any repeating pattern at all.&lt;/p&gt;
&lt;p&gt;The square root of two is 1.41421356237309504880&amp;#8230;, and the digital sum of the first one hundred decimal digits is 475.&lt;/p&gt;
&lt;p&gt;For the first one hundred natural numbers, find the total of the digital sums of the first one hundred decimal digits for all the irrational square roots.&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;python&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #dc143c;&quot;&gt;math&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;from&lt;/span&gt; sympy &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;import&lt;/span&gt; sqrt,evalf
a=&lt;span style=&quot;color: #008000;&quot;&gt;filter&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;lambda&lt;/span&gt; x:&lt;span style=&quot;color: #dc143c;&quot;&gt;math&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;sqrt&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;gt;&lt;/span&gt;int&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #dc143c;&quot;&gt;math&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;sqrt&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;span style=&quot;color: #008000;&quot;&gt;range&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff4500;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;in&lt;/span&gt; a:
	k=&lt;span style=&quot;color: #008000;&quot;&gt;list&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;sqrt&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;evalf&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;105&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
	k.&lt;span style=&quot;color: black;&quot;&gt;remove&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;'.'&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
	s=s+&lt;span style=&quot;color: #008000;&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;int&lt;/span&gt;,k&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;:&lt;span style=&quot;color: #ff4500;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;print&lt;/span&gt; s&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829760/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829760/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><wfw:commentRss>http://blog.4message.net/2009/02/20/projecteuler-80.html/feed</wfw:commentRss><slash:comments>0</slash:comments><description>It is well known that if the square root of a natural number is not an integer, then it is irrational. The decimal expansion of such square roots is infinite without any repeating pattern at all.
The square root of two is 1.41421356237309504880&amp;#8230;, and the digital sum of the first one hundred decimal digits is 475.
For [...]&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829760/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829760/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><category>Uncategorized</category><pubDate>Fri, 20 Feb 2009 22:39:51 +0800</pubDate><author>Cun Zhang</author><comments>http://blog.4message.net/2009/02/20/projecteuler-80.html#comments</comments><guid isPermaLink="false">http://blog.4message.net/?p=688</guid><dc:creator>Cun Zhang</dc:creator><fs:srclink>http://blog.4message.net/2009/02/20/projecteuler-80.html</fs:srclink><fs:srcfeed>http://blog.4message.net/feed</fs:srcfeed><fs:itemid>feedsky/apzc2529/~7024609/321829760/4784867</fs:itemid></item><item><title>Find the largest palindrome number</title><link>http://blog.4message.net/2009/02/02/find-the-largest-palindrome-number.html</link><content:encoded>&lt;p&gt;This question is from ProjectEuler 04.&lt;/p&gt;
&lt;p&gt;A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 &lt;img style=&quot;vertical-align: middle;&quot; src=&quot;http://projecteuler.net/images/symbol_times.gif&quot; border=&quot;0&quot; alt=&quot;×&quot; width=&quot;9&quot; height=&quot;9&quot; /&gt; 99.&lt;/p&gt;
&lt;p&gt;Find the largest palindrome made from the product of two 3-digit numbers.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;:&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;python&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;def&lt;/span&gt; palindromic&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;n&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
	s=&lt;span style=&quot;color: #008000;&quot;&gt;list&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;n&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;if&lt;/span&gt; s==s&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;::-&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;:
		&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;
	&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;else&lt;/span&gt;:
		&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt;
&amp;nbsp;
m,n=&lt;span style=&quot;color: #ff4500;&quot;&gt;999&lt;/span&gt;,&lt;span style=&quot;color: #ff4500;&quot;&gt;99&lt;/span&gt;
p=&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;range&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;m,n,-&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
	&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;for&lt;/span&gt; j &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;range&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;m,i-&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;,-&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
		&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;if&lt;/span&gt; palindromic&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;i&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
			p.&lt;span style=&quot;color: black;&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;i&lt;span style=&quot;color: #66cc66;&quot;&gt;*&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
			&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;break&lt;/span&gt;
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;print&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;p&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829763/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829763/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><wfw:commentRss>http://blog.4message.net/2009/02/02/find-the-largest-palindrome-number.html/feed</wfw:commentRss><slash:comments>0</slash:comments><description>This question is from ProjectEuler 04.
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91  99.
Find the largest palindrome made from the product of two 3-digit numbers.
Answer:

def palindromic&amp;#40;n&amp;#41;:
	s=list&amp;#40;str&amp;#40;n&amp;#41;&amp;#41;
	if s==s&amp;#91;::-1&amp;#93;:
		return 1
	else:
		return 0
&amp;#160;
m,n=999,99
p=&amp;#91;&amp;#93;
for i in range&amp;#40;m,n,-1&amp;#41;:
	for j in range&amp;#40;m,i-1,-1&amp;#41;:
		if palindromic&amp;#40;i*j&amp;#41;:
			p.append&amp;#40;i*j&amp;#41;
			break
print max&amp;#40;p&amp;#41;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829763/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829763/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><category>palindrome</category><category>python</category><category>Math</category><category>projecteuler</category><pubDate>Mon, 02 Feb 2009 14:48:51 +0800</pubDate><author>Cun Zhang</author><comments>http://blog.4message.net/2009/02/02/find-the-largest-palindrome-number.html#comments</comments><guid isPermaLink="false">http://blog.4message.net/?p=679</guid><dc:creator>Cun Zhang</dc:creator><fs:srclink>http://blog.4message.net/2009/02/02/find-the-largest-palindrome-number.html</fs:srclink><fs:srcfeed>http://blog.4message.net/feed</fs:srcfeed><fs:itemid>feedsky/apzc2529/~7024609/321829763/4784867</fs:itemid></item><item><title>A Python Programe for Decomposition of the Prime-factor Number</title><link>http://blog.4message.net/2009/01/08/a-python-programe-for-decomposition-of-the-prime-factor-number.html</link><content:encoded>&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;python&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: #dc143c;&quot;&gt;math&lt;/span&gt; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;import&lt;/span&gt; sqrt
&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;def&lt;/span&gt; isprime&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;n&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
	&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;if&lt;/span&gt; n==&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;:
		&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt;
	&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;elif&lt;/span&gt; n==&lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;or&lt;/span&gt; n==&lt;span style=&quot;color: #ff4500;&quot;&gt;3&lt;/span&gt;:
		&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;
	&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;elif&lt;/span&gt; n&lt;span style=&quot;color: #66cc66;&quot;&gt;%&lt;/span&gt;2==&lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;or&lt;/span&gt; n&lt;span style=&quot;color: #66cc66;&quot;&gt;%&lt;/span&gt;3==&lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;or&lt;/span&gt; sqrt&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;n&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;==&lt;span style=&quot;color: #008000;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;sqrt&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;n&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
		&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt;
	a=&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;
	N=&lt;span style=&quot;color: #008000;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;sqrt&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;n&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;+&lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt;
	&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;for&lt;/span&gt; x &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;range&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;3&lt;/span&gt;,N,&lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
		&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;if&lt;/span&gt; n&lt;span style=&quot;color: #66cc66;&quot;&gt;%&lt;/span&gt;x==&lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt;:
			a=&lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt;
			&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;break&lt;/span&gt;
	&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; a&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;


&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;python&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;def&lt;/span&gt; factor&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;n&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
	result=&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;
	&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;while&lt;/span&gt; n&lt;span style=&quot;color: #66cc66;&quot;&gt;%&lt;/span&gt;2==&lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt;:
		result.&lt;span style=&quot;color: black;&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
		n=n/&lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt;
	&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;while&lt;/span&gt; n&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;=&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;:
		&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;if&lt;/span&gt; isprime&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;n&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
			result.&lt;span style=&quot;color: black;&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;n&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
			&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;break&lt;/span&gt;
		j=&lt;span style=&quot;color: #ff4500;&quot;&gt;3&lt;/span&gt;
		&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;range&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;j,&lt;span style=&quot;color: #008000;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;sqrt&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;n&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;+&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:
			&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;if&lt;/span&gt; n&lt;span style=&quot;color: #66cc66;&quot;&gt;%&lt;/span&gt;i==&lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt;:
				result.&lt;span style=&quot;color: black;&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
				n=n/i
				j=i
				&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;break&lt;/span&gt;
	&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; result&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829769/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829769/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><wfw:commentRss>http://blog.4message.net/2009/01/08/a-python-programe-for-decomposition-of-the-prime-factor-number.html/feed</wfw:commentRss><slash:comments>0</slash:comments><description>from math import sqrt
def isprime&amp;#40;n&amp;#41;:
	if n==1:
		return 0
	elif n==2 or n==3:
		return 1
	elif n%2==0 or n%3==0 or sqrt&amp;#40;n&amp;#41;==int&amp;#40;sqrt&amp;#40;n&amp;#41;&amp;#41;:
		return 0
	a=1
	N=int&amp;#40;sqrt&amp;#40;n&amp;#41;&amp;#41;+2
	for x in range&amp;#40;3,N,2&amp;#41;:
		if n%x==0:
			a=0
			break
	return a


def factor&amp;#40;n&amp;#41;:
	result=&amp;#91;&amp;#93;
	while n%2==0:
		result.append&amp;#40;2&amp;#41;
		n=n/2
	while n!=1:
		if isprime&amp;#40;n&amp;#41;:
			result.append&amp;#40;n&amp;#41;
			break
		j=3
		for i in range&amp;#40;j,int&amp;#40;sqrt&amp;#40;n&amp;#41;&amp;#41;+1,2&amp;#41;:
			if n%i==0:
				result.append&amp;#40;i&amp;#41;
				n=n/i
				j=i
				break
	return result&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/apzc2529/321829769/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/apzc2529/321829769/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><category>python</category><category>factor</category><category>Math</category><pubDate>Thu, 08 Jan 2009 11:40:07 +0800</pubDate><author>Cun Zhang</author><comments>http://blog.4message.net/2009/01/08/a-python-programe-for-decomposition-of-the-prime-factor-number.html#comments</comments><guid isPermaLink="false">http://blog.4message.net/?p=664</guid><dc:creator>Cun Zhang</dc:creator><fs:srclink>http://blog.4message.net/2009/01/08/a-python-programe-for-decomposition-of-the-prime-factor-number.html</fs:srclink><fs:srcfeed>http://blog.4message.net/feed</fs:srcfeed><fs:itemid>feedsky/apzc2529/~7024609/321829769/4784867</fs:itemid></item></channel></rss>