Given two positive numbers A and B. The task is to divide A by B and calculate the number of digits after decimal.
Example 1:
Input: A = 4, B = 5
Output: 1
Explaination: If 4 is divided by 5 the 
result is 0.8. So there is only 1 digit 
after decimal.
Example 2:
Input: A = 1, B = 3
Output: -1
Explaination: It's a recurring decimal when 
1 is divided by 3.
Your Task:
You do not need to read input or print anything. Your task is to complete the function countDecimal() which takes A and B as input parameters and returns the number of integers after the decimal point. It returns -1 if it is a recurring decimal.
Expected Time Complexity: O(B)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ A, B ≤ 10^{6}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def countDecimal(self, A, B):

        # code here

Solutions:
class Solution:

	def countDecimal(self, A, B):
		if A % B == 0:
			return 0
		c = str(A / B)
		if '.' in c:
			c = c.split('.')
		if 'e-' in c:
			c = c.split('e-')
			return int(c[1])
		if len(c[1]) >= 10:
			return -1
		return len(c[1])
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(A, B) = [int(x) for x in input().split()]
		ob = Solution()
		print(ob.countDecimal(A, B))