Problem 345
Count Multiples in a Range
Easy · 10 pts · Math
Problem
Count the integers X with L <= X <= R that are divisible by K. The range can be enormous (up to 10^18 numbers), so looping over it is impossible; use the fact that the multiples of K up to some number M are counted by floor(M / K). Use 64-bit integers.
Input
Three integers L, R and K.
Output
Print the number of multiples of K in [L, R].
Constraints
1 <= L <= R <= 10^18; 1 <= K <= 10^18
Example input
6 11 2
Example output
3
Explanation
Between 6 and 11 the multiples of 2 are 6, 8 and 10, so the answer is 3.