Counting integers divisible by either of two values
Count how many integers in a range are divisible by either of two numbers, adding each count and subtracting the multiples of the LCM that were counted twice.
The double count
Among the integers 1 through 30, ten are multiples of 3: 3, 6, 9 and so on to 30. Six are multiples of 5: 5, 10, 15, 20, 25 and 30. Adding the two counts gives 16, but some integers appear in both lists and have been counted twice. The numbers 15 and 30 are multiples of both 3 and 5. They must be counted once, not twice. The correct number of integers divisible by 3 or 5 is the sum of the individual counts minus the count of integers that satisfy both conditions. That is the inclusion-exclusion rule for two sets.
Finding the shared multiples with the LCM
An integer is divisible by both 3 and 5 exactly when it is divisible by their least common multiple. The LCM calculator returns 15 for 3 and 5, using lcm(a, b) equals the absolute value of a times b divided by gcd(a, b). Since 3 and 5 share no factor, their gcd is 1 and the LCM is just 15. The shared multiples therefore occur every 15 numbers: 15, 30, 45 and so on. In the range 1 to 30, this gives floor of 30 over 15, which is 2 shared multiples. The LCM sets the spacing of the overlaps, and the interval decides how many of them fit. A longer range, such as 1 through 90, would hold 6 shared multiples at the same spacing, while a shorter one, such as 1 through 14, would hold none.
Putting the counts together
The count of multiples of a number k up to N is the whole-number part of N divided by k. For 3 it is the whole-number part of 30 over 3, which is 10. For 5 it is 6. For the LCM 15 it is 2. The union is 10 plus 6 minus 2, which is 14. The basic calculator confirms 10 plus 6 equals 16, and 16 minus 2 equals 14. So 14 of the 30 integers are divisible by 3 or 5, and the other 16 are divisible by neither. Those 16 are found by subtracting 14 from 30. They are 1, 2, 4, 7, 8, 11, 13, 14, 16, 17, 19, 22, 23, 26, 28 and 29. Reading that list against the multiples confirms that none of the sixteen is divisible by 3 or by 5, and that no integer from 1 through 30 is missing from the two lists combined.
A pair whose gcd is not 1
Take 4 and 6 over the integers 1 through 100. The count of multiples of 4 is 25, and of 6 is 16, since 100 over 6 is about 16.67 and the whole-number part is 16. The LCM of 4 and 6 is 12, not 24, because the two share the factor 2. The LCM calculator returns 12. Multiples of 12 up to 100 number 8, since 8 times 12 is 96. The union is 25 plus 16 minus 8, which is 33. Using 24, the product, instead of the LCM would give 4 shared multiples and a wrong total of 37.
Another range, 2 and 3 up to 60
For multiples of 2 or 3 among 1 through 60, there are 30 multiples of 2, 20 multiples of 3 and 10 multiples of 6, the LCM. The union is 30 plus 20 minus 10, which is 40. The LCM calculator gives 6 for the pair. The basic calculator confirms 30 plus 20 as 50 and 50 minus 10 as 40. The remaining 20 integers are those not divisible by 2 or 3, namely those of the form 6k plus 1 or 6k plus 5. Seeing the structure in a second range helps confirm the method does not depend on the particular numbers. Because 2 and 3 are coprime, the LCM equals the product, 6, and the overlap count is the whole-number part of 60 over 6. When the divisors are coprime, using their product and using their LCM agree, which is why textbook examples often start with coprime pairs. The case of 4 and 6 above is the one that separates the two.
The endpoint convention
The example counts positive integers from 1 through 30 inclusive, so zero is excluded and 30 is included. Changing the range changes the counts. For a range from a to b inclusive, the number of multiples of k is the whole-number part of b over k minus the whole-number part of a minus 1 over k. If the range starts at 0, zero counts as a multiple of every integer and adds 1 to each count and to the overlap, which cancels in the union formula, but it changes the size of the range. State the endpoints before counting.
Three divisors need more care
For three divisors the pattern grows. The union equals the sum of the three single counts, minus the three pairwise overlap counts, plus the count of multiples of the LCM of all three. For 2, 3 and 5 up to 30, there are 15, 10 and 6 multiples, pairwise LCMs 6, 10 and 15 with 5, 3 and 2 multiples, and an LCM of all three of 30 with 1 multiple. The union is 31 minus 10 plus 1, or 22. Skipping the final addition back gives 21, which is wrong. The worksheet stays with two divisors for that reason.
Three errors in counting multiples
Three errors recur. The first is subtracting the multiples of the product instead of the LCM, which fails when the divisors share a factor. The second is rounding the quotient to the nearest integer, when the count requires rounding down. The third is forgetting to subtract the overlap, which overstates the answer: here it would give 16 rather than 14. A check that avoids all three is to list the multiples for a small range and count by hand, then compare. For 1 through 30, the list 3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24, 25, 27, 30 has 14 entries.
Scope of the result
The count describes integers in a finite inclusive interval and two divisors. It does not apply to an infinite range, where the share of integers divisible by 3 or 5 approaches 7 fifteenths, a fraction found from one third plus one fifth minus one fifteenth. In the finite case the exact count depends on where the interval ends, so 14 out of 30 differs a little from that fraction. The method also assumes whole-number divisors greater than zero. Divisors of zero or non-integers are outside its scope. The LCM calculator handles two integers, so a problem with more divisors is solved by combining pairwise values step by step. As a practical illustration, the same arithmetic counts how many days in a 30-day month fall on a 3-day or a 5-day cycle, if both cycles start on day 3 and day 5 respectively, which gives 14 days with at least one event.
Reproduce the checks
Shared-multiple spacing
Open the LCM calculator and enter:
- First integer
3- Second integer
5
Expected output:
Least common multiple
15The overlap occurs at multiples of fifteen.
Separate count sum
Open the Basic calculator and enter:
- First number
10- Operation
add- Second number
6
Expected output:
Result
16The two overlap values are currently counted twice.
Distinct union count
Open the Basic calculator and enter:
- First number
16- Operation
subtract- Second number
2
Expected output:
Result
14Subtract their duplicate contribution once.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.