Files
PAT/source/html/b1019.html
T

30 lines
3.3 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
数字黑洞
<div class="ques-view"><p>给定任一个各位数字不完全相同的 4 位正整数,如果我们先把 4 个数字按非递增排序,再按非递减排序,然后用第 1 个数字减第 2 个数字,将得到一个新的数字。一直重复这样做,我们很快会停在有“数字黑洞”之称的 <code>6174</code>,这个神奇的数字也叫 Kaprekar 常数。</p>
<p>例如,我们从<code>6767</code>开始,将得到</p>
<pre><code>7766 - 6677 = 1089
9810 - 0189 = 9621
9621 - 1269 = 8352
8532 - 2358 = 6174
7641 - 1467 = 6174
... ...
</code></pre><p>现给定任意 4 位正整数,请编写程序演示到达黑洞的过程。</p>
<h3 id="-">输入格式:</h3>
<p>输入给出一个 <span class="katex"><span class="katex-mathml"><math><mrow><mo>(</mo><mn>0</mn><mo separator="true">,</mo><mn>1</mn><msup><mn>0</mn><mn>4</mn></msup><mo>)</mo></mrow>(0, 10^4)</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.8141079999999999em;"></span><span class="strut bottom" style="height:1.064108em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mopen">(</span><span class="mord mathrm">0</span><span class="mpunct">,</span><span class="mord mathrm">1</span><span class="mord"><span class="mord mathrm">0</span><span class="msupsub"><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped mtight"><span class="mord mathrm mtight">4</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span></span><span class="mclose">)</span></span></span></span> 区间内的正整数 <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi></mrow>N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span>。</p>
<h3 id="-">输出格式:</h3>
<p>如果 <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi></mrow>N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span> 的 4 位数字全相等,则在一行内输出 <code>N - N = 0000</code>;否则将计算的每一步在一行内输出,直到 <code>6174</code> 作为差出现,输出格式见样例。注意每个数字按 <code>4</code> 位数格式输出。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">6767
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">7766 - 6677 = 1089
9810 - 0189 = 9621
9621 - 1269 = 8352
8532 - 2358 = 6174
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">2222
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">2222 - 2222 = 0000
</code></pre>
</div>