You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# [2698.Find the Punishment Number of an Integer][title]
2
+
3
+
## Description
4
+
Given a positive integer `n`, return the **punishment number** of `n`.
5
+
6
+
The **punishment number** of `n` is defined as the sum of the squares of all integers `i` such that:
7
+
8
+
-`1 <= i <= n`
9
+
- 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`.
10
+
11
+
**Example 1:**
12
+
13
+
```
14
+
Input: n = 10
15
+
Output: 182
16
+
Explanation: There are exactly 3 integers i in the range [1, 10] that satisfy the conditions in the statement:
17
+
- 1 since 1 * 1 = 1
18
+
- 9 since 9 * 9 = 81 and 81 can be partitioned into 8 and 1 with a sum equal to 8 + 1 == 9.
19
+
- 10 since 10 * 10 = 100 and 100 can be partitioned into 10 and 0 with a sum equal to 10 + 0 == 10.
20
+
Hence, the punishment number of 10 is 1 + 81 + 100 = 182
21
+
```
22
+
23
+
**Example 2:**
24
+
25
+
```
26
+
Input: n = 37
27
+
Output: 1478
28
+
Explanation: There are exactly 4 integers i in the range [1, 37] that satisfy the conditions in the statement:
29
+
- 1 since 1 * 1 = 1.
30
+
- 9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1.
31
+
- 10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0.
32
+
- 36 since 36 * 36 = 1296 and 1296 can be partitioned into 1 + 29 + 6.
33
+
Hence, the punishment number of 37 is 1 + 81 + 100 + 1296 = 1478
0 commit comments