Count of Multiples of A , B or C less than or equal to N | Function to return the gcd of a and b ; Function to return the count of integers from the range [ 1 , num ] which are divisible by either a , b or c ; Calculate the number of terms divisible by a , b and c then remove the terms which are divisible by both ( a , b ) or ( b , c ) or ( c , a ) and then add the numbers which are divisible by a , b and c ; Driver code
def gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 ) : NEW_LINE INDENT return b ; NEW_LINE DEDENT return gcd ( b % a , a ) ; NEW_LINE DEDENT def lcm ( x , y ) : NEW_LINE INDENT return ( x * y ) // gcd ( x , y ) NEW_LINE DEDENT def divTermCount ( a , b , c , num ) : NEW_LINE INDENT return ( num // a + num // b + num // c - num // lcm ( a , b ) - num // lcm ( c , b ) - num // lcm ( a , c ) + num // ( lcm ( lcm ( a , b ) , c ) ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 7 ; b = 3 ; c = 5 ; n = 100 ; NEW_LINE print ( divTermCount ( a , b , c , n ) ) ; NEW_LINE DEDENT