Count total divisors of A or B in a given range | Utility function to find GCD of two numbers ; Utility function to find LCM of two numbers ; Function to calculate all divisors in given range ; Find LCM of a and b ; Find common divisor by using LCM ; Driver Code
< ? php function gcd ( $ a , $ b ) { return ( $ a % $ b ) ? gcd ( $ b , $ a % $ b ) : $ b ; } function FindLCM ( $ a , $ b ) { return ( $ a * $ b ) / gcd ( $ a , $ b ) ; } function rangeDivisor ( $ m , $ n , $ a , $ b ) { $ lcm = FindLCM ( $ a , $ b ) ; $ a_divisor = $ n / $ a - ( $ m - 1 ) / $ a ; $ b_divisor = $ n / $ b - ( $ m - 1 ) / $ b ; $ common_divisor = $ n / $ lcm - ( $ m - 1 ) / $ lcm ; $ ans = $ a_divisor + $ b_divisor - $ common_divisor ; return $ ans ; } $ m = 3 ; $ n = 11 ; $ a = 2 ; $ b = 3 ; print ( ceil ( rangeDivisor ( $ m , $ n , $ a , $ b ) ) ) ; echo " STRNEWLINE " ; $ m = 11 ; $ n = 1000000 ; $ a = 6 ; $ b = 35 ; print ( ceil ( rangeDivisor ( $ m , $ n , $ a , $ b ) ) ) ; ? >