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
function reverse ( num ) { var rev = 0 ; while ( num > 0 ) { var r = parseInt ( ( num % 10 ) ) ; rev = rev * 10 + r ; num = parseInt ( num / 10 ) ; } return rev ; } function count ( N , A , B ) { var l = Math . pow ( 10 , N - 1 ) , r = Math . pow ( 10 , N ) - 1 ; if ( l == 1 ) l = 0 ; var ans = 0 ; for ( i = l ; i <= r ; i ++ ) { var even_sum = 0 , odd_sum = 0 ; var itr = 0 , num = reverse ( i ) ; while ( num > 0 ) { if ( itr % 2 == 0 ) odd_sum += num % 10 ; else even_sum += num % 10 ; num = parseInt ( num / 10 ) ; itr ++ ; } if ( even_sum % A == 0 && odd_sum % B == 0 ) ans ++ ; } return ans ; } var N = 2 , A = 5 , B = 3 ; document . write ( count ( N , A , B ) ) ;