If the current digit is zero and nonz is 1 , we can 't place it
if ( d == 0 && nonz ) continue ; var currSum = sum + d ; var currRem = ( rem * 10 + d ) % m ; var currF = ( tight != 0 || ( d < num [ pos ] ) ) ? 1 : 0 ; ans += count ( pos + 1 , currSum , currRem , currF , ( nonz != 0 d != 0 ) ? 1 : 0 , num ) ; } dp [ pos ] [ sum ] [ rem ] [ tight ] = ans ; return ans ; }