Count numbers up to C that can be reduced to 0 by adding or subtracting A or B | Function to calculate GCD of the two numbers a and b ; Base Case ; Recursively find the GCD ; Function to count the numbers up to C that can be reduced to 0 by adding or subtracting A or B ; Stores GCD of A and B ; Stores the count of multiples of g in the range ( 0 , C ] ; Print the result ; Driver Code
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function countDistinctNumbers ( A , B , C ) { var g = gcd ( A , B ) ; var count = C / g ; document . write ( count ) ; } var A = 2 , B = 3 , C = 5 ; countDistinctNumbers ( A , B , C ) ;