Junction Numbers | Python3 program for the above approach ; Function to find the sum Of digits of N ; To store sum of N and sumOfdigitsof ( N ) ; extracting digit ; Function to check Junction numbers ; To store count of ways n can be represented as i + SOD ( i ) ; Driver Code ; Function Call
import math NEW_LINE def sum1 ( n ) : NEW_LINE INDENT sum1 = 0 NEW_LINE while ( n != 0 ) : NEW_LINE INDENT r = n % 10 NEW_LINE sum1 = sum1 + r NEW_LINE n = n // 10 NEW_LINE DEDENT return sum1 NEW_LINE DEDENT def isJunction ( n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( i + sum1 ( i ) == n ) : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT DEDENT return count >= 2 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 111 NEW_LINE if ( isJunction ( n ) == 1 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT