Skip to content

Commit

Permalink
Site updated: 2024-03-13 09:17:29
Browse files Browse the repository at this point in the history
  • Loading branch information
oyoanan committed Mar 13, 2024
1 parent 380b48e commit 1a61108
Show file tree
Hide file tree
Showing 12 changed files with 807 additions and 8 deletions.
6 changes: 6 additions & 0 deletions 2024/03/08/LeetCode03/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@ <h2 id="知识点"><a href="#知识点" class="headerlink" title="知识点"></a
<article class="post-prev col-6">


<a href="/2024/03/13/PAT03/" title="PAT03:数素数">
<i class="iconfont icon-arrowleft"></i>
<span class="hidden-mobile">PAT03:数素数</span>
<span class="visible-mobile">上一篇</span>
</a>

</article>
<article class="post-next col-6">

Expand Down
652 changes: 652 additions & 0 deletions 2024/03/13/PAT03/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion archives/2024/02/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@


<div class="list-group">
<p class="h4">共计 6 篇文章</p>
<p class="h4">共计 7 篇文章</p>
<hr>


Expand Down
8 changes: 7 additions & 1 deletion archives/2024/03/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,20 @@


<div class="list-group">
<p class="h4">共计 6 篇文章</p>
<p class="h4">共计 7 篇文章</p>
<hr>




<p class="h5">2024</p>

<a href="/2024/03/13/PAT03/" class="list-group-item list-group-item-action">
<time>03-13</time>
<div class="list-group-item-title">PAT03:数素数</div>
</a>


<a href="/2024/03/08/LeetCode03/" class="list-group-item list-group-item-action">
<time>03-08</time>
<div class="list-group-item-title">LeetCode03:最长连续序列</div>
Expand Down
8 changes: 7 additions & 1 deletion archives/2024/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,20 @@


<div class="list-group">
<p class="h4">共计 6 篇文章</p>
<p class="h4">共计 7 篇文章</p>
<hr>




<p class="h5">2024</p>

<a href="/2024/03/13/PAT03/" class="list-group-item list-group-item-action">
<time>03-13</time>
<div class="list-group-item-title">PAT03:数素数</div>
</a>


<a href="/2024/03/08/LeetCode03/" class="list-group-item list-group-item-action">
<time>03-08</time>
<div class="list-group-item-title">LeetCode03:最长连续序列</div>
Expand Down
8 changes: 7 additions & 1 deletion archives/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,20 @@


<div class="list-group">
<p class="h4">共计 6 篇文章</p>
<p class="h4">共计 7 篇文章</p>
<hr>




<p class="h5">2024</p>

<a href="/2024/03/13/PAT03/" class="list-group-item list-group-item-action">
<time>03-13</time>
<div class="list-group-item-title">PAT03:数素数</div>
</a>


<a href="/2024/03/08/LeetCode03/" class="list-group-item list-group-item-action">
<time>03-08</time>
<div class="list-group-item-title">LeetCode03:最长连续序列</div>
Expand Down
8 changes: 7 additions & 1 deletion categories/PAT/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,20 @@


<div class="list-group">
<p class="h4">共计 2 篇文章</p>
<p class="h4">共计 3 篇文章</p>
<hr>




<p class="h5">2024</p>

<a href="/2024/03/13/PAT03/" class="list-group-item list-group-item-action">
<time>03-13</time>
<div class="list-group-item-title">PAT03:数素数</div>
</a>


<a href="/2024/03/07/PAT02/" class="list-group-item list-group-item-action">
<time>03-07</time>
<div class="list-group-item-title">PAT02:数字分类</div>
Expand Down
11 changes: 10 additions & 1 deletion categories/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@

<a href="/categories/PAT/" class="category-count col-2 col-md-1 col-xm-1">
<i class="iconfont icon-articles"></i>
<span>2</span>
<span>3</span>
</a>

<div class="category-collapse collapse " id="collapse-157181ffcabbeae54bb036e489bc2b77"
Expand All @@ -313,6 +313,15 @@



<a href="/2024/03/13/PAT03/" title="PAT03:数素数"
class="list-group-item list-group-item-action
">
<span class="category-post">PAT03:数素数</span>
</a>




<a href="/2024/03/07/PAT02/" title="PAT02:数字分类"
class="list-group-item list-group-item-action
">
Expand Down
69 changes: 69 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,75 @@



<div class="row mx-auto index-card">


<div class="col-12 col-md-4 m-auto index-img">
<a href="/2024/03/13/PAT03/" target="_self">
<img src="https://an-hexo-blog.oss-cn-beijing.aliyuncs.com/img/202403021855958.jpeg" srcset="/img/loading.gif" lazyload alt="PAT03:数素数">
</a>
</div>

<article class="col-12 col-md-8 mx-auto index-info">
<h2 class="index-header">

<a href="/2024/03/13/PAT03/" target="_self">
PAT03:数素数
</a>
</h2>


<a class="index-excerpt " href="/2024/03/13/PAT03/" target="_self">
<div>
3.数素数题目题目描述 1令Pi表示第i(i从1开始计数)个素数。现任给两个正整数M &lt;= N &lt;= 10000,请输出PM到PN的所有素数。 输入描述: 1输入在一行中给出M和N,其间以空格分隔。 输出描述: 1输出从PM到PN的所有素数,每10个数字占1行,其间以空格分隔,但行末不得有多余空格。 输入例子: 15 27 输出例子: 12311 13 17 19 23 29
</div>
</a>

<div class="index-btm post-metas">

<div class="post-meta mr-3">
<i class="iconfont icon-date"></i>
<time datetime="2024-03-13 09:16" pubdate>
2024-03-13
</time>
</div>


<div class="post-meta mr-3 d-flex align-items-center">
<i class="iconfont icon-category"></i>


<span class="category-chains">



<span class="category-chain">

<a href="/categories/PAT/" class="category-chain-item">PAT</a>



</span>


</span>

</div>


<div class="post-meta">
<i class="iconfont icon-tags"></i>

<a href="/tags/Python/">#Python</a>

<a href="/tags/%E9%A2%98%E5%BA%93/">#题库</a>

</div>

</div>
</article>
</div>

<div class="row mx-auto index-card">


Expand Down
27 changes: 27 additions & 0 deletions local-search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@



<entry>
<title>PAT03:数素数</title>
<link href="/2024/03/13/PAT03/"/>
<url>/2024/03/13/PAT03/</url>

<content type="html"><![CDATA[<h1 id="3-数素数"><a href="#3-数素数" class="headerlink" title="3.数素数"></a>3.数素数</h1><h2 id="题目"><a href="#题目" class="headerlink" title="题目"></a>题目</h2><p><strong>题目描述</strong></p><figure class="highlight abnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs abnf">令Pi表示第i(i从<span class="hljs-number">1</span>开始计数)个素数。现任给两个正整数M &lt;<span class="hljs-operator">=</span> N &lt;<span class="hljs-operator">=</span> <span class="hljs-number">10000</span>,请输出PM到PN的所有素数。<br></code></pre></td></tr></table></figure><p><strong>输入描述:</strong></p><figure class="highlight excel"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs excel">输入在一行中给出M和<span class="hljs-built_in">N</span>,其间以空格分隔。<br></code></pre></td></tr></table></figure><p><strong>输出描述:</strong></p><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs">输出从PM到PN的所有素数,每10个数字占1行,其间以空格分隔,但行末不得有多余空格。<br></code></pre></td></tr></table></figure><p><strong>输入例子:</strong></p><figure class="highlight basic"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs basic"><span class="hljs-symbol">5 </span><span class="hljs-number">27</span><br></code></pre></td></tr></table></figure><p><strong>输出例子:</strong></p><figure class="highlight basic"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs basic"><span class="hljs-symbol">11 </span><span class="hljs-number">13</span> <span class="hljs-number">17</span> <span class="hljs-number">19</span> <span class="hljs-number">23</span> <span class="hljs-number">29</span> <span class="hljs-number">31</span> <span class="hljs-number">37</span> <span class="hljs-number">41</span> <span class="hljs-number">43</span><br><span class="hljs-symbol">47 </span><span class="hljs-number">53</span> <span class="hljs-number">59</span> <span class="hljs-number">61</span> <span class="hljs-number">67</span> <span class="hljs-number">71</span> <span class="hljs-number">73</span> <span class="hljs-number">79</span> <span class="hljs-number">83</span> <span class="hljs-number">89</span><br><span class="hljs-symbol">97 </span><span class="hljs-number">101</span> <span class="hljs-number">103</span><br></code></pre></td></tr></table></figure><h2 id="题解"><a href="#题解" class="headerlink" title="题解"></a>题解</h2><h3 id="1-我的解法"><a href="#1-我的解法" class="headerlink" title="(1)我的解法"></a>(1)我的解法</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> sys<br><br><span class="hljs-keyword">def</span> <span class="hljs-title function_">suShu</span>(<span class="hljs-params">num</span>):<br> <span class="hljs-keyword">if</span> num &lt;= <span class="hljs-number">1</span>:<br> <span class="hljs-keyword">return</span> <span class="hljs-literal">False</span><br> n = <span class="hljs-built_in">int</span>(num**<span class="hljs-number">0.5</span>) + <span class="hljs-number">1</span><br> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>,n+<span class="hljs-number">1</span>):<br> <span class="hljs-keyword">if</span> num % i == <span class="hljs-number">0</span> <span class="hljs-keyword">and</span> num != i:<br> <span class="hljs-keyword">return</span> <span class="hljs-literal">False</span><br> <span class="hljs-keyword">return</span> <span class="hljs-literal">True</span> <br><br><span class="hljs-keyword">def</span> <span class="hljs-title function_">outNum</span>(<span class="hljs-params">nums</span>):<br> <span class="hljs-keyword">for</span> i,num <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(nums,start=<span class="hljs-number">1</span>):<br> <span class="hljs-keyword">if</span> i % <span class="hljs-number">10</span> == <span class="hljs-number">0</span>:<br> <span class="hljs-built_in">print</span>(num)<br> <span class="hljs-keyword">else</span>:<br> <span class="hljs-keyword">if</span> i == <span class="hljs-built_in">len</span>(nums):<br> <span class="hljs-built_in">print</span>(num,end=<span class="hljs-string">&#x27;&#x27;</span>)<br> <span class="hljs-keyword">else</span>:<br> <span class="hljs-built_in">print</span>(num,end=<span class="hljs-string">&#x27; &#x27;</span>)<br> <br><br><span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> sys.stdin:<br> res = []<br> m,n = <span class="hljs-built_in">map</span>(<span class="hljs-built_in">int</span>,line.split())<br> num = <span class="hljs-number">1</span><br> count = <span class="hljs-number">0</span><br> <span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>:<br> num += <span class="hljs-number">1</span><br> <span class="hljs-keyword">if</span> suShu(num):<br> count += <span class="hljs-number">1</span><br> <span class="hljs-keyword">if</span> m&lt;=count&lt;=n:<br> res.append(num)<br> <span class="hljs-keyword">elif</span> count &gt; n:<br> <span class="hljs-keyword">break</span><br> outNum(res)<br><br></code></pre></td></tr></table></figure><h3 id="(2)其他解法"><a href="#(2)其他解法" class="headerlink" title="(2)其他解法"></a>(2)其他解法</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">from</span> math <span class="hljs-keyword">import</span> sqrt<br><span class="hljs-keyword">import</span> sys<br><br><span class="hljs-keyword">def</span> <span class="hljs-title function_">isPrime</span>(<span class="hljs-params">x</span>):<br> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>, <span class="hljs-built_in">int</span>(sqrt(x))+<span class="hljs-number">1</span>):<br> <span class="hljs-keyword">if</span> x % i == <span class="hljs-number">0</span>:<br> <span class="hljs-keyword">return</span> <span class="hljs-literal">False</span><br> <span class="hljs-keyword">return</span> <span class="hljs-literal">True</span><br><br><span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> sys.stdin:<br> no = line.split(<span class="hljs-string">&#x27; &#x27;</span>)<br> m, n = <span class="hljs-built_in">int</span>(no[<span class="hljs-number">0</span>]), <span class="hljs-built_in">int</span>(no[<span class="hljs-number">1</span>])<br> i,count = <span class="hljs-number">2</span>,<span class="hljs-number">0</span><br> <span class="hljs-keyword">while</span> count &lt; n :<br> <span class="hljs-keyword">if</span> isPrime(i):<br> count += <span class="hljs-number">1</span><br> <span class="hljs-keyword">if</span> count &gt;= m:<br> <span class="hljs-keyword">if</span> (count-m+<span class="hljs-number">1</span>)%<span class="hljs-number">10</span> != <span class="hljs-number">0</span>:<br> <span class="hljs-built_in">print</span>(i,end=<span class="hljs-string">&#x27; &#x27;</span>),<br> <span class="hljs-keyword">else</span> :<br> <span class="hljs-built_in">print</span>(i)<br> i += <span class="hljs-number">1</span><br><br></code></pre></td></tr></table></figure><h2 id="知识点"><a href="#知识点" class="headerlink" title="知识点"></a>知识点</h2><p><strong>素数(质数)</strong></p><blockquote><p>指在大于1的<a href="https://baike.baidu.com/item/%E8%87%AA%E7%84%B6%E6%95%B0/385394?fromModule=lemma_inlink">自然数</a>中,除了1和它本身以外不再有其他<a href="https://baike.baidu.com/item/%E5%9B%A0%E6%95%B0/9539111?fromModule=lemma_inlink">因数</a>的自然数。</p></blockquote><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">def</span> <span class="hljs-title function_">isPrime</span>(<span class="hljs-params">x</span>):<br> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>, <span class="hljs-built_in">int</span>(sqrt(x))+<span class="hljs-number">1</span>):<br> <span class="hljs-keyword">if</span> x % i == <span class="hljs-number">0</span>:<br> <span class="hljs-keyword">return</span> <span class="hljs-literal">False</span><br> <span class="hljs-keyword">return</span> <span class="hljs-literal">True</span><br></code></pre></td></tr></table></figure><p><strong>打印分隔符</strong></p><blockquote><p>打印结束时使用的行尾符号,默认是换行符 <code>\n</code>。</p></blockquote><p><code>sep</code>是间隔中有符号,末尾不会有符号</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-built_in">print</span>(item1, item2, item3, sep=<span class="hljs-string">&#x27; 分隔符 &#x27;</span>)<br></code></pre></td></tr></table></figure><p><code>end</code>是每个元素后面都有符号,末尾也会有</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-built_in">print</span>(item1, item2, end=<span class="hljs-string">&#x27; 结尾符 &#x27;</span>)<br></code></pre></td></tr></table></figure><p><strong>每10个处理一次</strong></p><blockquote><p>1、结果列表中的元素索引 % 10 &#x3D;&#x3D; 0</p><p>2、(输出序数-输出开始数+1)%10 &#x3D;&#x3D; 0</p></blockquote><p><strong>开根</strong></p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python">num**<span class="hljs-number">0.5</span><br></code></pre></td></tr></table></figure><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">from</span> math <span class="hljs-keyword">import</span> sqrt<br>sqrt(num)<br></code></pre></td></tr></table></figure>]]></content>


<categories>

<category>PAT</category>

</categories>


<tags>

<tag>Python</tag>

<tag>题库</tag>

</tags>

</entry>



<entry>
<title>LeetCode03:最长连续序列</title>
<link href="/2024/03/08/LeetCode03/"/>
Expand Down
Loading

0 comments on commit 1a61108

Please sign in to comment.