2698. Find the Punishment Number of an Integer Medium
1/**
2 * [2698] Find the Punishment Number of an Integer
3 *
4 * Given a positive integer n, return the punishment number of n.
5 * The punishment number of n is defined as the sum of the squares of all integers i such that:
6 *
7 * 1 <= i <= n
8 * The decimal representation of i * i can be partitioned into contiguous substrings such that the sum of the integer values of these substrings equals i.
9 *
10 *
11 * <strong class="example">Example 1:
12 *
13 * Input: n = 10
14 * Output: 182
15 * Explanation: There are exactly 3 integers i that satisfy the conditions in the statement:
16 * - 1 since 1 * 1 = 1
17 * - 9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1.
18 * - 10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0.
19 * Hence, the punishment number of 10 is 1 + 81 + 100 = 182
20 *
21 * <strong class="example">Example 2:
22 *
23 * Input: n = 37
24 * Output: 1478
25 * Explanation: There are exactly 4 integers i that satisfy the conditions in the statement:
26 * - 1 since 1 * 1 = 1.
27 * - 9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1.
28 * - 10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0.
29 * - 36 since 36 * 36 = 1296 and 1296 can be partitioned into 1 + 29 + 6.
30 * Hence, the punishment number of 37 is 1 + 81 + 100 + 1296 = 1478
31 *
32 *
33 * Constraints:
34 *
35 * 1 <= n <= 1000
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/find-the-punishment-number-of-an-integer/
41// discuss: https://leetcode.com/problems/find-the-punishment-number-of-an-integer/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn punishment_number(n: i32) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_2698() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.