Recurrence relation
for i in range ( start , 10 ) : NEW_LINE INDENT min = 0 NEW_LINE if ( ( st i ) > 0 ) : NEW_LINE INDENT min = 1 NEW_LINE DEDENT else : NEW_LINE INDENT min = 0 NEW_LINE DEDENT res += countNum ( N - 1 , ( sum + i ) % K , K , min , dp ) NEW_LINE dp [ N ] [ sum ] [ st ] = res NEW_LINE DEDENT return dp [ N ] [ sum ] [ st ] NEW_LINE