Skip to content

2698. Find the Punishment Number of an Integer #1317

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to determine the "punishment number" of a given integer n. The punishment number is defined as the sum of the squares of all integers i (where 1 <= i <= n) such that the decimal representation of i * i can be partitioned into contiguous substrings whose sum equals i.

Approach

  1. Iterate through each integer i from 1 to n: For each integer, compute its square and convert the square into a string.
  2. Check if the square can be partitioned: For each integer i, check if its square can be split into contiguous substrings such that the sum of these substrings equals i. This check is performed using a recursive helper function.
  3. Recursive helper function: This function attempts to split the st…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Feb 15, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Feb 15, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants