Deloitte | OA | Punishment Number
Anonymous User
1253
Jan 02, 2023
Jan 02, 2023
Punishment Number
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 <= N- square of
xcan be converted toxby dividing it into integers and taking sum of them.
For example:- square of
9i.e.,81can be converted to9like this:8 + 1 = 9. - square of
99i.e.,9801can be converted to99like this:98 + 0 + 1 = 99. - square of
10i.e.,100can be converted to10like this:10 + 0 = 10. - square of
36i..e,1296can be converted to36like this:1 + 29 + 6 = 36.
- square of
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
Comments (10)


