Given an integer N, find the punishment number of N.
Punishment number of number N is defined as sum of squares of all x's such that:
1 <= x <= Nx can be converted to x by dividing it into integers and taking sum of them.9 i.e., 81 can be converted to 9 like this: 8 + 1 = 9.99 i.e., 9801 can be converted to 99 like this: 98 + 0 + 1 = 99.10 i.e., 100 can be converted to 10 like this: 10 + 0 = 10.36 i..e, 1296 can be converted to 36 like this: 1 + 29 + 6 = 36.Example 1:
Input: N = 10
Output: 182
Explanation: Among all the numbers from 1 to 10, following numbers follows the conditions:
- square of 1 is already 1.
- square of 9 i.e., 81 can be converted to 9 like this: 8 + 1 = 9.
- square of 10 i.e., 100 can be converted to 10 like this: 10 + 0 = 10.
So sum of squares of 1, 9 and 10 is 1 + 81 + 100 = 182. Example 2:
Input: N = 37
Output: 1478
Explanation: Among all the numbers from 1 to 10, following numbers follows the conditions:
- square of 1 is already 1.
- square of 9 i.e., 81 can be converted to 9 like this: 8 + 1 = 9.
- square of 10 i.e., 100 can be converted to 10 like this: 10 + 0 = 10.
- square of 36 i.e., 1296 can be converted to 36 like this: 1 + 29 + 6 = 36.
So sum of squares of 1, 9, 10 and 36 is 1 + 81 + 100 + 1296 = 1478. Constraints:
1 <= N <= 10000