java.lang.Object
g2401_2500.s2457_minimum_addition_to_make_integer_beautiful.Solution

public class Solution extends Object
2457 - Minimum Addition to Make Integer Beautiful.<p>Medium</p> <p>You are given two positive integers <code>n</code> and <code>target</code>.</p> <p>An integer is considered <strong>beautiful</strong> if the sum of its digits is less than or equal to <code>target</code>.</p> <p>Return the <em>minimum <strong>non-negative</strong> integer</em> <code>x</code> <em>such that</em> <code>n + x</code> <em>is beautiful</em>. The input will be generated such that it is always possible to make <code>n</code> beautiful.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 16, target = 6</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> Initially n is 16 and its digit sum is 1 + 6 = 7. After adding 4, n becomes 20 and digit sum becomes 2 + 0 = 2. It can be shown that we can not make n beautiful with adding non-negative integer less than 4.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 467, target = 6</p> <p><strong>Output:</strong> 33</p> <p><strong>Explanation:</strong> Initially n is 467 and its digit sum is 4 + 6 + 7 = 17. After adding 33, n becomes 500 and digit sum becomes 5 + 0 + 0 = 5. It can be shown that we can not make n beautiful with adding non-negative integer less than 33.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 1, target = 1</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> Initially n is 1 and its digit sum is 1, which is already smaller than or equal to target.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 10<sup>12</sup></code></li> <li><code>1 <= target <= 150</code></li> <li>The input will be generated such that it is always possible to make <code>n</code> beautiful.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • makeIntegerBeautiful

      public long makeIntegerBeautiful(long n, int target)
    • sumOfDigits

      public long sumOfDigits(long n)