Calculate total count of sequences of length odd_count with sum divisible by B where cannot be zero
let dp1 = new Array ( odd_count ) ; for ( var i = 0 ; i < dp1 . length ; i ++ ) { dp1 [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < odd_count ; i ++ ) { for ( var j = 0 ; j < max_sum + 1 ; j ++ ) { dp1 [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= 9 ; i ++ ) dp1 [ 0 ] [ i % B ] ++ ; for ( let i = 1 ; i < odd_count ; i ++ ) { for ( let j = 0 ; j <= 9 ; j ++ ) { for ( let k = 0 ; k <= max_sum ; k ++ ) { if ( dp1 [ i - 1 ] [ k ] > 0 ) dp1 [ i ] [ ( j + k ) % B ] += dp1 [ i - 1 ] [ k ] ; } } }