Count of values chosen for X such that N is reduced to 0 after given operations | Function to check if the value of X reduces N to 0 or not ; Update the value of N as N - x ; Check if x is a single digit integer ; Function to find the number of values X such that N can be reduced to 0 after performing the given operations ; Number of digits in N ; Stores the count of value of X ; Iterate over all possible value of X ; Check if x follow the conditions ; Return the total count ; Driver Code
def check ( x , N ) : NEW_LINE INDENT while True : NEW_LINE INDENT N -= x NEW_LINE if len ( str ( x ) ) == 1 : NEW_LINE INDENT break NEW_LINE DEDENT x = sum ( list ( map ( int , str ( x ) ) ) ) NEW_LINE DEDENT if len ( str ( x ) ) == 1 and N == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT def countNoOfsuchX ( N ) : NEW_LINE INDENT k = len ( str ( N ) ) NEW_LINE count = 0 NEW_LINE for x in range ( N - k * ( k + 1 ) * 5 , N + 1 ) : NEW_LINE INDENT if check ( x , N ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT N = 9939 NEW_LINE print ( countNoOfsuchX ( N ) ) NEW_LINE