Find the Punishment Number of an Integer
Given a positive integer n, return the punishment number of n.
The punishment number of n is defined as the sum of the squares of all integers i such that:
1 <= i <= n- The decimal representation of
i * ican be partitioned into contiguous substrings such that the sum of the integer values of these substrings equalsi.
Example 1
Input
n = 10Output
182There are exactly 3 integers in the range [1, 10] that satisfy the conditions, so the punishment number is 1 + 81 + 100 = 182.
Example 2
Input
n = 37Output
1478There are exactly 4 integers in the range [1, 37] that satisfy the conditions, so the punishment number is 1 + 81 + 100 + 1296 = 1478.
Constraints
- 1 <= n <= 1000