Multiple of Numbers

24 Views Asked by At

I am working on a problem in which 1 to N numbers are given and one have to count how many numbers between 1 to N are divisible by A or B but not by both.Where A and B are any natural number.Ho can i solve this problem efficiently rather than checking every number.

1

There are 1 best solutions below

0
On

This is simple first find how many numbers upto $\Bbb{N}$ are divisible by A and B. Add them. Now there are some numbers which are divisible by both, so find number divisible by there LCM and subtract it.