1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/哈沙德数 [harshad-number].html
2024-04-07 13:02:43 +08:00

36 lines
1.4 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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.

<p>如果一个整数能够被其各个数位上的数字之和整除,则称之为<strong> 哈沙德数</strong>Harshad number。给你一个整数 <code>x</code> 。如果 <code>x</code><strong>哈沙德数 </strong>,则返回<em> </em><code>x</code> 各个数位上的数字之和,否则,返回<em> </em><code>-1</code></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">x = 18</span></p>
<p><strong>输出:</strong> <span class="example-io">9</span></p>
<p><strong>解释:</strong></p>
<p><code>x</code> 各个数位上的数字之和为 <code>9</code><code>18</code> 能被 <code>9</code> 整除。因此 <code>18</code> 是哈沙德数,答案是 <code>9</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">x = 23</span></p>
<p><strong>输出:</strong> <span class="example-io">-1</span></p>
<p><strong>解释:</strong></p>
<p><code>x</code> 各个数位上的数字之和为 <code>5</code><code>23</code> 不能被 <code>5</code> 整除。因此 <code>23</code> 不是哈沙德数,答案是 <code>-1</code></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= x &lt;= 100</code></li>
</ul>