Count how many integers in the inclusive range [1, n] are divisible by a or by b (or both). Use inclusion-exclusion: floor(n/a) + floor(n/b) - floor(n/lcm(a,b)).
One line: three integers n, a, b.
One line: the count of integers in [1, n] divisible by a or b.
Example 1
Input
10 2 3
Expected
7
Explanation
Multiples of 2: 5; of 3: 3; of 6: 1; total 5+3-1=7.
Example 2
Input
15 5 5
Expected
3
Explanation
a and b are equal, so lcm=5 and the count is 3+3-3=3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →