Lynch | Python3 implementation for the above approach ; Function to check the divisibility of the number by its digit . ; If the digit divides the number then return true else return false . ; Function to check if all digits of n divide it or not ; Taking the digit of the number into digit var . ; Function to check if N has all distinct digits ; Create an array of size 10 and initialize all elements as false . This array is used to check if a digit is already seen or not . ; Traverse through all digits of given number ; Find the last digit ; If digit is already seen , return false ; Mark this digit as seen ; Remove the last digit from number ; Function to check Lynch - Bell numbers ; Driver Code ; Given number N ; Function call
import math NEW_LINE def checkDivisibility ( n , digit ) : NEW_LINE INDENT return ( ( digit != 0 ) and ( ( n % digit ) == 0 ) ) NEW_LINE DEDENT def isAllDigitsDivide ( n ) : NEW_LINE INDENT temp = n NEW_LINE while ( temp >= 1 ) : NEW_LINE INDENT digit = int ( temp % 10 ) NEW_LINE if ( checkDivisibility ( n , digit ) == False ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT temp = temp / 10 NEW_LINE DEDENT return 1 NEW_LINE DEDENT def isAllDigitsDistinct ( n ) : NEW_LINE INDENT arr = [ 0 ] * 10 NEW_LINE while ( n >= 1 ) : NEW_LINE INDENT digit = int ( n % 10 ) NEW_LINE if ( arr [ digit ] ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT arr [ digit ] = 1 NEW_LINE n = int ( n / 10 ) NEW_LINE DEDENT return 1 NEW_LINE DEDENT def isLynchBell ( n ) : NEW_LINE INDENT return ( isAllDigitsDivide ( n ) and isAllDigitsDistinct ( n ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 12 NEW_LINE if isLynchBell ( N ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT