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 leteger ; 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 total count ; Driver Code
function check ( x , N ) { while ( true ) { N -= x ; if ( x < 10 ) break ; let temp2 = 0 ; while ( x > 0 ) { temp2 += ( x % 10 ) ; x = Math . floor ( x / 10 ) ; } x = temp2 ; } if ( ( x < 10 ) && ( N == 0 ) ) { return true ; } return false ; } function countNoOfsuchX ( N ) { let k = Math . floor ( Math . log10 ( N ) ) + 1 ; let count = 1 ; for ( let x = ( N - ( k * ( k + 1 ) * 5 ) ) ; x <= N ; x ++ ) { if ( check ( x , N ) ) { count += 1 ; } } return count ; } let N = 9399 ; document . write ( countNoOfsuchX ( N ) ) ;