Skip to content

Commit

Permalink
Update code highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
weilycoder committed Nov 5, 2024
1 parent a69d55d commit 9326497
Show file tree
Hide file tree
Showing 22 changed files with 1,436 additions and 319 deletions.
228 changes: 191 additions & 37 deletions authors/weily/feed.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion authors/weily/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ <h1 class="gblog-post__title">

<span class="flex align-center no-wrap gblog-post__meta--readtime">
<svg class="gblog-icon gblog_timer"><use xlink:href="#gblog_timer"></use></svg>
<span class="gblog-post__tag">1 min read</span>
<span class="gblog-post__tag">2 min read</span>
</span>


Expand Down
489 changes: 402 additions & 87 deletions feed.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ <h1 class="gblog-post__title">

<span class="flex align-center no-wrap gblog-post__meta--readtime">
<svg class="gblog-icon gblog_timer"><use xlink:href="#gblog_timer"></use></svg>
<span class="gblog-post__tag">1 min read</span>
<span class="gblog-post__tag">2 min read</span>
</span>


Expand Down Expand Up @@ -921,7 +921,7 @@ <h1 class="gblog-post__title">

<span class="flex align-center no-wrap gblog-post__meta--readtime">
<svg class="gblog-icon gblog_timer"><use xlink:href="#gblog_timer"></use></svg>
<span class="gblog-post__tag">1 min read</span>
<span class="gblog-post__tag">2 min read</span>
</span>


Expand Down
34 changes: 28 additions & 6 deletions post/bezouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"url" : "https://weilycoder.github.io/post/bezouts/",
"headline": "辗转相除法和裴蜀定理",
"description": "数论基础第二弹!",
"wordCount" : "314",
"wordCount" : "324",
"license": "CC BY-SA 4.0",
"inLanguage": "en",
"isFamilyFriendly": "true",
Expand Down Expand Up @@ -465,8 +465,15 @@ <h1 class="gblog-post__title">辗转相除法和裴蜀定理</h1>
<p>既然公约数相同,那么最大公约数也相同。</p>
</blockquote>
<p>容易写出递归版:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="kt">int</span> <span class="nf">gcd</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">b</span><span class="o">?</span> <span class="n">gcd</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">a</span> <span class="o">%</span> <span class="n">b</span><span class="p">)</span><span class="o">:</span> <span class="n">a</span><span class="p">;</span> <span class="p">}</span>
</span></span></code></pre></div><div class="flex align-center gblog-post__anchorwrap">
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-Cpp" data-lang="Cpp"><span class="line"><span class="cl"><span class="kt">int</span> <span class="nf">gcd</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">b</span><span class="o">?</span> <span class="n">gcd</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">a</span> <span class="o">%</span> <span class="n">b</span><span class="p">)</span><span class="o">:</span> <span class="n">a</span><span class="p">;</span> <span class="p">}</span></span></span></code></pre></td></tr></table>
</div>
</div>
<div class="flex align-center gblog-post__anchorwrap">
<h3 id="时间复杂度"
>
时间复杂度
Expand Down Expand Up @@ -527,16 +534,31 @@ <h1 class="gblog-post__title">辗转相除法和裴蜀定理</h1>
<p>故解为 $(x_0,y_0-\left\lfloor\dfrac{a}{b}\right\rfloor x_0)$,由数学归纳法,对任意 $\gcd(a,b)=1$,均能构造 $(x,y)$ 使 $ax+by=1$,进而原命题得证。</p>
<p>裴蜀定理的逆定理也成立。</p>
<p>容易写出代码:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="kt">int</span> <span class="nf">exgcd</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">,</span> <span class="kt">int</span> <span class="o">&amp;</span><span class="n">x</span><span class="p">,</span> <span class="kt">int</span> <span class="o">&amp;</span><span class="n">y</span><span class="p">)</span> <span class="p">{</span>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-Cpp" data-lang="Cpp"><span class="line"><span class="cl"><span class="kt">int</span> <span class="nf">exgcd</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">,</span> <span class="kt">int</span> <span class="o">&amp;</span><span class="n">x</span><span class="p">,</span> <span class="kt">int</span> <span class="o">&amp;</span><span class="n">y</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl"> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl"> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"> <span class="k">return</span> <span class="n">a</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"> <span class="p">}</span>
</span></span><span class="line"><span class="cl"> <span class="kt">int</span> <span class="n">d</span> <span class="o">=</span> <span class="n">exgcd</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">a</span> <span class="o">%</span> <span class="n">b</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"> <span class="n">y</span> <span class="o">-=</span> <span class="n">a</span> <span class="o">/</span> <span class="n">b</span> <span class="o">*</span> <span class="n">x</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"> <span class="k">return</span> <span class="n">d</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>由于函数在求最大公因数的过程中计算可行解,这种算法被称作扩展欧几里得算法。</p>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></td></tr></table>
</div>
</div>
<p>由于函数在求最大公因数的过程中计算可行解,这种算法被称作扩展欧几里得算法。</p>
<p>有时我们担心,扩展欧几里得算法给出的可行解过大,使得变量发生溢出;幸运的是,可以证明,上述算法给出的解满足 $|x|&lt;b,|y|&lt;a.$</p>
<p>归纳法易证。</p>
<div class="flex align-center gblog-post__anchorwrap">
Expand Down
18 changes: 18 additions & 0 deletions post/bin-inversion/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,24 @@ <h1 class="gblog-post__title">二项式反演学习笔记</h1>








<span class="gblog-footer__item gblog-footer__item--row">

<svg class="gblog-icon gblog_link"><use xlink:href="#gblog_link"></use></svg>

<a
href="https://github.com/thegeeklab/hugo-geekblog"
class="gblog-footer__link"
>
Theme
</a>
</span>





Expand Down
Loading

0 comments on commit 9326497

Please sign in to comment.