2081. Sum of k-Mirror Numbers Hard
1/**
2 * [2081] Sum of k-Mirror Numbers
3 *
4 * A k-mirror number is a positive integer without leading zeros that reads the same both forward and backward in base-10 as well as in base-k.
5 *
6 * For example, 9 is a 2-mirror number. The representation of 9 in base-10 and base-2 are 9 and 1001 respectively, which read the same both forward and backward.
7 * On the contrary, 4 is not a 2-mirror number. The representation of 4 in base-2 is 100, which does not read the same both forward and backward.
8 *
9 * Given the base k and the number n, return the sum of the n smallest k-mirror numbers.
10 *
11 * Example 1:
12 *
13 * Input: k = 2, n = 5
14 * Output: 25
15 * Explanation:
16 * The 5 smallest 2-mirror numbers and their representations in base-2 are listed as follows:
17 * base-10 base-2
18 * 1 1
19 * 3 11
20 * 5 101
21 * 7 111
22 * 9 1001
23 * Their sum = 1 + 3 + 5 + 7 + 9 = 25.
24 *
25 * Example 2:
26 *
27 * Input: k = 3, n = 7
28 * Output: 499
29 * Explanation:
30 * The 7 smallest 3-mirror numbers are and their representations in base-3 are listed as follows:
31 * base-10 base-3
32 * 1 1
33 * 2 2
34 * 4 11
35 * 8 22
36 * 121 11111
37 * 151 12121
38 * 212 21212
39 * Their sum = 1 + 2 + 4 + 8 + 121 + 151 + 212 = 499.
40 *
41 * Example 3:
42 *
43 * Input: k = 7, n = 17
44 * Output: 20379000
45 * Explanation: The 17 smallest 7-mirror numbers are:
46 * 1, 2, 3, 4, 5, 6, 8, 121, 171, 242, 292, 16561, 65656, 2137312, 4602064, 6597956, 6958596
47 *
48 *
49 * Constraints:
50 *
51 * 2 <= k <= 9
52 * 1 <= n <= 30
53 *
54 */
55pub struct Solution {}
56
57// problem: https://leetcode.com/problems/sum-of-k-mirror-numbers/
58// discuss: https://leetcode.com/problems/sum-of-k-mirror-numbers/discuss/?currentPage=1&orderBy=most_votes&query=
59
60// submission codes start here
61
62impl Solution {
63 pub fn k_mirror(k: i32, n: i32) -> i64 {
64
65 }
66}
67
68// submission codes end
69
70#[cfg(test)]
71mod tests {
72 use super::*;
73
74 #[test]
75 fn test_2081() {
76 }
77}
78
Back
© 2025 bowen.ge All Rights Reserved.