Check if N can be represented as sum of positive integers containing digit D at least once | Function to check if N contains digit D in it ; Iterate until N is positive ; Find the last digit ; If the last digit is the same as digit D ; Return false ; Function to check if the value of N can be represented as sum of integers having digit d in it ; Iterate until N is positive ; Check if N contains digit D or not ; Subtracting D from N ; Return false ; Driver Code
def findDigit ( N , D ) : NEW_LINE INDENT while ( N > 0 ) : NEW_LINE INDENT a = N % 10 NEW_LINE if ( a == D ) : NEW_LINE INDENT return True NEW_LINE DEDENT N /= 10 NEW_LINE DEDENT return False NEW_LINE DEDENT def check ( N , D ) : NEW_LINE INDENT while ( N > 0 ) : NEW_LINE INDENT if ( findDigit ( N , D ) == True ) : NEW_LINE INDENT return True NEW_LINE DEDENT N -= D NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 24 NEW_LINE D = 7 NEW_LINE if ( check ( N , D ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT