Computer Science, asked by SANRIDDHA, 2 days ago

Write a program to accept any 2 numbers and print all common multiples of 2 numbers up to the
product of the numbers.

Plz solve fast

Answers

Answered by Anonymous
0
  1. Answer: Given a range from L to R and every Xth tile is painted black and every the tile is painted white in that range from L to R. If a tile is painted both white and black, then it is considered to be painted grey. The task is to find the number of tiles that are colored grey in range L to R (both inclusive).

Explanation:

Since every multiple of X is black and every multiple of Y is white. Any tile which is a multiple of both X and Y would be grey. The terms that are divisible by both X and Y are the terms that are divisible by the lcm of X and Y.

Lcm can be found out using the following formula:  

 

lcm = (x*y) / gcd(x, y)

GCD can be computed in logn time using Euclid’s algorithm. The number of multiples of lcm in range L to R can be found by using a common trick of:  

 

count(L, R) = count(R) - count(L-1)

Similar questions