2827. Number of Beautiful Integers in the Range Hard

@problem@discussion
#Math#Dynamic Programming



1/**
2 * [2827] Number of Beautiful Integers in the Range
3 *
4 * You are given positive integers low, high, and k.
5 * A number is beautiful if it meets both of the following conditions:
6 * 
7 * 	The count of even digits in the number is equal to the count of odd digits.
8 * 	The number is divisible by k.
9 * 
10 * Return the number of beautiful integers in the range [low, high].
11 *  
12 * <strong class="example">Example 1:
13 * 
14 * Input: low = 10, high = 20, k = 3
15 * Output: 2
16 * Explanation: There are 2 beautiful integers in the given range: [12,18]. 
17 * - 12 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.
18 * - 18 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.
19 * Additionally we can see that:
20 * - 16 is not beautiful because it is not divisible by k = 3.
21 * - 15 is not beautiful because it does not contain equal counts even and odd digits.
22 * It can be shown that there are only 2 beautiful integers in the given range.
23 * 
24 * <strong class="example">Example 2:
25 * 
26 * Input: low = 1, high = 10, k = 1
27 * Output: 1
28 * Explanation: There is 1 beautiful integer in the given range: [10].
29 * - 10 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 1.
30 * It can be shown that there is only 1 beautiful integer in the given range.
31 * 
32 * <strong class="example">Example 3:
33 * 
34 * Input: low = 5, high = 5, k = 2
35 * Output: 0
36 * Explanation: There are 0 beautiful integers in the given range.
37 * - 5 is not beautiful because it is not divisible by k = 2 and it does not contain equal even and odd digits.
38 * 
39 *  
40 * Constraints:
41 * 
42 * 	0 < low <= high <= 10^9
43 * 	0 < k <= 20
44 * 
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/number-of-beautiful-integers-in-the-range/
49// discuss: https://leetcode.com/problems/number-of-beautiful-integers-in-the-range/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54    pub fn number_of_beautiful_integers(low: i32, high: i32, k: i32) -> i32 {
55        0
56    }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_2827() {
67    }
68}
69


Back
© 2025 bowen.ge All Rights Reserved.