Count common elements in two arrays containing multiples of N and M | Recursive function to find gcd using euclidean algorithm ; Function to find lcm of two numbers using gcd ; Driver code
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function lcm ( n , m ) { return ( n * m ) / gcd ( n , m ) ; } var n = 2 , m = 3 , k = 5 ; document . write ( parseInt ( k / lcm ( n , m ) ) ) ;