2457. Minimum Addition to Make Integer Beautiful Medium

@problem@discussion
#Math#Greedy



1/**
2 * [2457] Minimum Addition to Make Integer Beautiful
3 *
4 * You are given two positive integers n and target.
5 * An integer is considered beautiful if the sum of its digits is less than or equal to target.
6 * Return the minimum non-negative integer x such that n + x is beautiful. The input will be generated such that it is always possible to make n beautiful.
7 *  
8 * <strong class="example">Example 1:
9 * 
10 * Input: n = 16, target = 6
11 * Output: 4
12 * Explanation: 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.
13 * 
14 * <strong class="example">Example 2:
15 * 
16 * Input: n = 467, target = 6
17 * Output: 33
18 * Explanation: 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.
19 * 
20 * <strong class="example">Example 3:
21 * 
22 * Input: n = 1, target = 1
23 * Output: 0
24 * Explanation: Initially n is 1 and its digit sum is 1, which is already smaller than or equal to target.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= n <= 10^12
30 * 	1 <= target <= 150
31 * 	The input will be generated such that it is always possible to make n beautiful.
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/
37// discuss: https://leetcode.com/problems/minimum-addition-to-make-integer-beautiful/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn make_integer_beautiful(n: i64, target: i32) -> i64 {
43        
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_2457() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.