Count Multiples
EasyPractice library · +10 XPbinary searchmath
Given three positive integers A, B, and K, find the count of integers X such that A <= X <= B and X is divisible by K.
For example, if A=10, B=25, and K=5, the numbers divisible by K are 10, 15, 20, 25. The count is 4.
Print a single integer: the count of such numbers.
Input
A single line containing three space-separated positive integers A, B, K.
Output
A single integer representing the count of multiples of K in the range [A, B].
Constraints
1 <= A <= B <= 10^9, 1 <= K <= 10^9
Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests
Example 1
Input
10 25 5
Output
4
Numbers divisible by 5 in [10, 25] are 10, 15, 20, 25. Count is 4.
Example 2
Input
1 10 3
Output
3
Numbers divisible by 3 in [1, 10] are 3, 6, 9. Count is 3.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
10 25 5
Example 2 input
1 10 3