i **lucky** if the decimal digits of i * i can be cut into pieces of consecutive digits whose values add up to i. For example, 36 is lucky: 36 * 36 = 1296 and 1 + 29 + 6 = 36. A piece may start with a zero, and leaving the digits uncut is allowed too.
Given limit, return the sum of the squares of all lucky numbers from 1 to limit inclusive.limit=9 → 82
1 works (1 = 1) and so does 9 (81 → 8 + 1 = 9). The answer is 1 + 81 = 82.
limit=45 → 3503
The fitting numbers are 1, 9, 10 (100 → 10 + 0), 36 (1296 → 1 + 29 + 6) and 45 (2025 → 20 + 25). Their squares add up to 1 + 81 + 100 + 1296 + 2025 = 3503.
limit=2 → 1
2 does not fit, since 4 cannot add up to 2. Only 1 remains.
limit=9
82
Run checks the first 3 tests in your browser. Submit checks all 24 tests on the server, hidden ones included.