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
def gcd ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a NEW_LINE DEDENT return gcd ( b , a % b ) NEW_LINE DEDENT def countDistinctNumbers ( A , B , C ) : NEW_LINE INDENT g = gcd ( A , B ) NEW_LINE count = C // g NEW_LINE print ( count ) NEW_LINE DEDENT A = 2 NEW_LINE B = 3 NEW_LINE C = 5 NEW_LINE countDistinctNumbers ( A , B , C ) NEW_LINE