Print all numbers up to N having product of digits equal to K | Function to find the product of digits of a number ; Stores the product of digits of a number ; Return the product ; Function to print all numbers upto N having product of digits equal to K ; Stores whether any number satisfying the given conditions exists or not ; Iterate over the range [ 1 , N ] ; If product of digits of arr [ i ] is equal to K or not ; Print that number ; If no numbers are found ; Driver Code ; Given value of N & K ; Function call to print all numbers from [ 1 , N ] with product of digits K
def productOfDigits ( N ) : NEW_LINE INDENT product = 1 ; NEW_LINE while ( N != 0 ) : NEW_LINE INDENT product = product * ( N % 10 ) ; NEW_LINE N = N // 10 ; NEW_LINE DEDENT return product ; NEW_LINE DEDENT def productOfDigitsK ( N , K ) : NEW_LINE INDENT flag = 0 ; NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT if ( K == productOfDigits ( i ) ) : NEW_LINE INDENT print ( i , end = " ▁ " ) ; NEW_LINE flag = 1 ; NEW_LINE DEDENT DEDENT if ( flag == 0 ) : NEW_LINE INDENT print ( " - 1" ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 500 ; K = 10 ; NEW_LINE productOfDigitsK ( N , K ) ; NEW_LINE DEDENT