Given two numbers A and B which define a range, where A <= B. Find the count of total numbers in the given range [A … B] divisible by M.
Example 1:
Input: A = 6, B = 15, M = 3
Output: 4 
Explanation: 6, 9, 12, 15 are divisible
by 3.Hence answer is 4.
Example 2:
Input: A = 25, B = 100, M = 30
Output: 3
Explanation: 30, 60, 90 are divisible
by 30.Hence answer is 3.
Your Task:  
You dont need to read input or print anything. Complete the function countDivisibles() which takes n as input parameter and returns the count of total numbers in the given range [A … B] divisible by M.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1<= A, B, M <=10^{6}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3
class Solution:
    def countDivisibles (ob, A, B, M):
        # code here 

Solutions:
class Solution:

	def countDivisibles(ob, A, B, M):
		a = A // M
		b = B // M
		if A % M == 0:
			return b - a + 1
		return b - a


from math import floor

class Solution:

	def countDivisibles(ob, A, B, M):
		return (B - A) // M + 1 if A % M == 0 else B // M - (A - 1) // M


class Solution:

	def countDivisibles(ob, A, B, M):
		(s, e) = (A // M, B // M)
		if A % M == 0 and B % M == 0 or (A % M == 0 and B % M != 0):
			return e - s + 1
		return e - s


class Solution:

	def countDivisibles(ob, A, B, M):
		a = int(A / M)
		b = int(B / M)
		m = M
		if A % m != 0 and B % m == 0:
			return b - a
		elif A % m != 0 and B % m != 0:
			return b - a
		else:
			return b - a + 1


class Solution:

	def countDivisibles(ob, A, B, M):
		x = A + M - A % M if A % M != 0 else A
		return len(range(x, B + 1, M))


class Solution:

	def countDivisibles(ob, A, B, M):
		return B // M - (A - 1) // M


class Solution:

	def countDivisibles(ob, A, B, M):
		count = 0
		num = (B - B % M - (A + (M - A % M))) / M
		if A % M == 0:
			count = 2
		else:
			count = 1
		return count + int(num)


class Solution:

	def countDivisibles(ob, A, B, M):
		count = 0
		i = A
		while i <= B:
			if i % M == 0:
				i += M
				count += 1
			else:
				i += 1
		return count


class Solution:

	def countDivisibles(ob, a, b, m):
		if a % m == 0:
			return b // m - a // m + 1
		else:
			return b // m - a // m


class Solution:

	def countDivisibles(ob, A, B, M):
		if A % M != 0:
			return B // M - A // M
		else:
			return B // M - A // M + 1


import math

class Solution:

	def countDivisibles(ob, A, B, M):
		c1 = math.floor(B // M)
		c2 = math.ceil(A // M)
		if c2 * M < A:
			c2 += 1
		if c2 == 0:
			c2 += 1
		if c2 < c1:
			return c1 - c2 + 1
		elif c1:
			return 1
		else:
			return 0


class Solution:

	def countDivisibles(ob, A, B, M):
		c = 0
		for i in range(A, B):
			if i % M == 0:
				c = i
				break
		count = 0
		while c <= B:
			count += 1
			c += M
		return count


class Solution:

	def countDivisibles(ob, A, B, M):
		k = B % M
		r = A % M
		if r == 0:
			return (B - A - k) // M + 1
		return (B - k - A + r) // M


class Solution:

	def countDivisibles(ob, A, B, M):
		a = A // M
		b = B // M
		if A % M == 0:
			return b - a + 1
		else:
			return b - a
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(A, B, M) = input().split()
		A = int(A)
		B = int(B)
		M = int(M)
		ob = Solution()
		print(ob.countDivisibles(A, B, M))


class Solution:

	def countDivisibles(ob, A, B, M):
		return B // M - (A - 1) // M
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(A, B, M) = input().split()
		A = int(A)
		B = int(B)
		M = int(M)
		ob = Solution()
		print(ob.countDivisibles(A, B, M))


import math

class Solution:

	def countDivisibles(ob, A, B, M):
		if A % M == 0:
			return B // M - A // M + 1
		return B // M - A // M


class Solution:

	def countDivisibles(ob, A, B, M):
		max_count = 0
		min_count = 0
		while max_count == 0:
			if B % M == 0:
				max_count = B // M
			B -= 1
		while min_count == 0:
			if A % M == 0:
				min_count = A // M
			A += 1
		return max_count - min_count + 1


class Solution:

	def countDivisibles(ob, A, B, M):
		c = int(B / M) - int(A / M)
		if A % M == 0:
			c += 1
		return c


class Solution:

	def countDivisibles(ob, A, B, M):
		divnum = 0
		while A <= B:
			if A % M == 0:
				divnum += 1
				A += M
			elif A % M != 0:
				A += 1
		return divnum


class Solution:

	def countDivisibles(ob, A, B, M):
		output = 0
		divisor = M
		while divisor < A:
			divisor = M + divisor
		while divisor <= B:
			output = output + 1
			divisor = divisor + M
		return output


class Solution:

	def countDivisibles(ob, A, B, M):
		numbTwo = B - B % M
		dividend = int(A / M)
		if A % M != 0:
			dividend = dividend + 1
		numbOne = M * dividend
		numberOneRem = int(numbOne / M)
		numberTwoRem = int(numbTwo / M)
		return numberTwoRem - numberOneRem + 1