Count of N | Function to calculate and return the reverse of the number ; Function to calculate the total count of N - digit numbers satisfying the necessary conditions ; Initialize two variables ; Calculate the sum of odd and even positions ; Check for divisibility ; Return the answer ; Driver Code
def reverse ( num ) : NEW_LINE INDENT rev = 0 ; NEW_LINE while ( num > 0 ) : NEW_LINE INDENT r = int ( num % 10 ) ; NEW_LINE rev = rev * 10 + r ; NEW_LINE num = num // 10 ; NEW_LINE DEDENT return rev ; NEW_LINE DEDENT def count ( N , A , B ) : NEW_LINE INDENT l = int ( pow ( 10 , N - 1 ) ) ; NEW_LINE r = int ( pow ( 10 , N ) - 1 ) ; NEW_LINE if ( l == 1 ) : NEW_LINE INDENT l = 0 ; NEW_LINE DEDENT ans = 0 ; NEW_LINE for i in range ( l , r + 1 ) : NEW_LINE INDENT even_sum = 0 ; NEW_LINE odd_sum = 0 ; NEW_LINE itr = 0 ; NEW_LINE num = reverse ( i ) ; NEW_LINE while ( num > 0 ) : NEW_LINE INDENT if ( itr % 2 == 0 ) : NEW_LINE INDENT odd_sum += num % 10 ; NEW_LINE DEDENT else : NEW_LINE INDENT even_sum += num % 10 ; NEW_LINE DEDENT num = num // 10 ; NEW_LINE itr += 1 ; NEW_LINE DEDENT if ( even_sum % A == 0 and odd_sum % B == 0 ) : NEW_LINE INDENT ans += 1 ; NEW_LINE DEDENT DEDENT return ans ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 2 ; NEW_LINE A = 5 ; NEW_LINE B = 3 ; NEW_LINE print ( count ( N , A , B ) ) ; NEW_LINE DEDENT