java.lang.Object
g2601_2700.s2698_find_the_punishment_number_of_an_integer.Solution

public class Solution extends Object
2698 - Find the Punishment Number of an Integer.<p>Medium</p> <p>Given a positive integer <code>n</code>, return <em>the <strong>punishment number</strong></em> of <code>n</code>.</p> <p>The <strong>punishment number</strong> of <code>n</code> is defined as the sum of the squares of all integers <code>i</code> such that:</p> <ul> <li><code>1 <= i <= n</code></li> <li>The decimal representation of <code>i * i</code> can be partitioned into contiguous substrings such that the sum of the integer values of these substrings equals <code>i</code>.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 10</p> <p><strong>Output:</strong> 182</p> <p><strong>Explanation:</strong> There are exactly 3 integers i that satisfy the conditions in the statement:</p> <ul> <li>1 since 1 * 1 = 1</li> <li>9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1.</li> <li>10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0.</li> </ul> <p>Hence, the punishment number of 10 is 1 + 81 + 100 = 182</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 37</p> <p><strong>Output:</strong> 1478</p> <p><strong>Explanation:</strong> There are exactly 4 integers i that satisfy the conditions in the statement:</p> <ul> <li>1 since 1 * 1 = 1.</li> <li>9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1.</li> <li>10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0.</li> <li>36 since 36 * 36 = 1296 and 1296 can be partitioned into 1 + 29 + 6.</li> </ul> <p>Hence, the punishment number of 37 is 1 + 81 + 100 + 1296 = 1478</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • punishmentNumber

      public int punishmentNumber(int n)