mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
53 lines
2.1 KiB
HTML
53 lines
2.1 KiB
HTML
<p>You are given a string <code>num</code> which represents a <strong>positive</strong> integer, and an integer <code>t</code>.</p>
|
|
|
|
<p>A number is called <strong>zero-free</strong> if <em>none</em> of its digits are 0.</p>
|
|
|
|
<p>Return a string representing the <strong>smallest</strong> <strong>zero-free</strong> number greater than or equal to <code>num</code> such that the <strong>product of its digits</strong> is divisible by <code>t</code>. If no such number exists, return <code>"-1"</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">num = "1234", t = 256</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">"1488"</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>The smallest zero-free number that is greater than 1234 and has the product of its digits divisible by 256 is 1488, with the product of its digits equal to 256.</p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">num = "12355", t = 50</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">"12355"</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>12355 is already zero-free and has the product of its digits divisible by 50, with the product of its digits equal to 150.</p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">num = "11111", t = 26</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">"-1"</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>No number greater than 11111 has the product of its digits divisible by 26.</p>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>2 <= num.length <= 2 * 10<sup>5</sup></code></li>
|
|
<li><code>num</code> consists only of digits in the range <code>['0', '9']</code>.</li>
|
|
<li><code>num</code> does not contain leading zeros.</li>
|
|
<li><code>1 <= t <= 10<sup>14</sup></code></li>
|
|
</ul>
|