Find count of numbers from 0 to n which satisfies the given equation for a value K | Function to find the values ; Calculate the LCM ; Calculate the multiples of lcm ; Find the values which satisfies the given condition ; Subtract the extra values ; Return the final result ; Driver code
def findAns ( a , b , n ) : NEW_LINE INDENT lcm = ( a * b ) // __gcd ( a , b ) ; NEW_LINE multiples = ( n // lcm ) + 1 ; NEW_LINE answer = max ( a , b ) * multiples ; NEW_LINE lastvalue = lcm * ( n // lcm ) + max ( a , b ) ; NEW_LINE if ( lastvalue > n ) : NEW_LINE INDENT answer = answer - ( lastvalue - n - 1 ) ; NEW_LINE DEDENT return answer ; NEW_LINE DEDENT def __gcd ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a ; NEW_LINE DEDENT else : NEW_LINE INDENT return __gcd ( b , a % b ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 1 ; NEW_LINE b = 13 ; NEW_LINE n = 500 ; NEW_LINE print ( findAns ( a , b , n ) ) ; NEW_LINE DEDENT