decimal-help

Bosky often helps his younger brother Nitin with his home work and also clears his doubts.

Today, Nitin learned about proper fractions. He went a step forward and tried to represent the same proper fraction in its decimal form, but runs into problems. He now seeks help from his brother Bosky.

Nitin is a very sincere learner, thus he wants his brother to help him but doesn't want him to completely solve the problem. He goes to his brother Bosky and asks him to help him wherever he gets stuck while representing the proper fraction in decimal expansion by telling the next digit in the decimal expansion.

Though Bosky is a bit busy today with his school project, he doesn't want to disappoint his brother. He is familiar with your brilliant programming skills and asks you to create a program to help his brother, which can output R th digit in the decimal expansion for a given proper fraction \frac{N}{D}.

Input:

Input will contain a number T denoting the number of test cases. 

Then T test cases follow, each one consisting 3 integers N D R
where N and D are numerator and denominator respectively.

Output

For each test case, output a single integer representing R th digit from the left in the decimal expansion. 

NOTE: The number is a proper fraction, hence the counting will always start after the decimal place. For eg. fraction \frac{1}{2} can be written as 0.5 so its first digit is 5 and all the digits after 5 are 0.

Constraints

1  ≤  T  ≤ 100

1  ≤ N ≤  D ≤ 1000000

1  ≤ R ≤ 1000000

SAMPLE INPUT
4
1 2 1
1 2 2
1 2 20
1234 12345 123

SAMPLE OUTPUT
5
0
0
7

Explanation

Case 1 : 1\; 2\; 1
\frac{1}{2} = 0.5 and 1st digit is 5.

Case 2 and 3: 
\frac{1}{2} = 0.50000000000000000000 
All digits after 5 are 0, hence the output is 0 and 0.

Case 4: Same logic!

Difficulty: EASY
Tags: Mathematics

Ad-hoc

Starter code:

Solutions:
def decimal(x,y,r):
	count = 0
	remainder = x%y
	quotient = 0
	while count<r and remainder != 0 :
		remainder = remainder*10
		quotient = remainder/y
		remainder = remainder%y
		count += 1
	if count<r:
		print(0)
	else:
		print(quotient)

for t in range(eval(input())):
	x = [int(i) for i in input().split()]
	decimal(x[0],x[1],x[2])


def nth_digit(a,b,c):
	r=a
	digit=0
	for _ in range(c):
		if r==0:
			return 0
		digit=(r*10)/b
		r=(r*10)%b
	return digit

for _ in range(eval(input())):
	temp=list(map(int,input().split()))
	a,b,c=temp[0],temp[1],temp[2]
	print(nth_digit(a,b,c))


def k(a,b,c):
	t=a
	d=0
	for i in range(c):
		if t== 0:
			return 0
		d=(t*10)/b
		t=(t*10)%b
	return d

for i in range(eval(input())):
	a,b,c=list(map(int,input().split()))
	print(k(a,b,c))


def fracnum(N,D,R):
	N = N % D
	
	v, d = abs(N)*10, abs(D)
	while R:
		(v, r, R) = ((v%d)*10, v//d, R-1)

	return r
name = int(input())
count = 0
while count < name :
	count += 1
	strings = input()
	words = strings.split()
	N = int(words[0])
	D = int(words[1])
	R = int(words[2])
	print(fracnum(N,D,R))


def nth_digit(a,b,c):
	r=a
	digit=0
	for _ in range(c):
		if r==0:
			return 0
		digit=(r*10)/b
		r=(r*10)%b
	return digit
 
for _ in range(eval(input())):
	temp=list(map(int,input().split()))
	a,b,c=temp[0],temp[1],temp[2]
	print(nth_digit(a,b,c))