#C1042. Count Divisible Numbers
Count Divisible Numbers
Count Divisible Numbers
You are given three integers a, b, and k. Your task is to compute the number of integers in the inclusive range \([a, b]\) that are divisible by \(k\). In other words, count the number of integers \(x\) such that:
\(a \le x \le b\) and \(k \mid x\)
One efficient approach is to determine the smallest number in the range which is divisible by \(k\) and the largest number in the range which is divisible by \(k\), and then calculate the count using the formula:
\(\text{count} = \frac{(\text{end} - \text{start})}{k} + 1\)
where start is the first multiple of \(k\) greater than or equal to \(a\) and end is the last multiple of \(k\) less than or equal to \(b\). If no such number exists, the answer is 0.
inputFormat
The input consists of a single line containing three space-separated integers:
a
: the lower bound of the range.b
: the upper bound of the range.k
: the divisor.
You can assume \(a \le b\) and all values are within appropriate limits.
outputFormat
Output a single integer representing the count of numbers in the range \([a, b]\) that are divisible by \(k\).
## sample1 10 2
5