Sum of all N digit palindromic numbers divisible by 9 formed using digits 1 to 9 | Function for finding count of N digits palindrome which are divisible by 9 ; If N is odd ; If N is even ; Function for finding sum of N digits palindrome which are divisible by 9 ; Count the possible number of palindrome ; Driver Code
def countPalindrome ( n ) : NEW_LINE INDENT count = 0 NEW_LINE if ( n % 2 == 1 ) : NEW_LINE INDENT count = pow ( 9 , ( n - 1 ) // 2 ) NEW_LINE DEDENT else : NEW_LINE INDENT count = pow ( 9 , ( n - 2 ) // 2 ) NEW_LINE DEDENT return count NEW_LINE DEDENT def sumPalindrome ( n ) : NEW_LINE INDENT count = countPalindrome ( n ) NEW_LINE res = 0 NEW_LINE if ( n == 1 ) : NEW_LINE INDENT return 9 NEW_LINE DEDENT if ( n == 2 ) : NEW_LINE INDENT return 99 NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT res = res * 10 + count * 5 NEW_LINE DEDENT return res NEW_LINE DEDENT n = 3 NEW_LINE print ( sumPalindrome ( n ) ) NEW_LINE