hdu 2117 Just a Numble

Problem Description

Now give you two integers n m, you just tell me the m-th number after radix point in 1/n,for example n=4,the first numble after point is 2,the second is 5,and all 0 followed.

Input

Each line of input will contain a pair of integers for n and m(1<=n<=10^7,1<=m<=10^5).

Output

For each line of input, your program should print a numble on a line,according to the above rules.

Sample Input

4 2
5 7
123 123

Sample Output

5
0
8


题目大意:输入两个整数n, m,求1/n第m位小数上的数值,例如n=4时,1/4 = 0.25,第1位小数为2,第2位小数为5,第3...位小数为0。

解题思路:(1*10) / 4 = 2,(1*10) % 4 = 2;(2*10) % 4 = 5,(5*10) % 4 = 0......

代码

#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
	int n, m;
	while (scanf("%d%d", &n, &m) != EOF)
	{
		int s = 1;
		int a = 0;
		while (m--)
		{
			s *= 10;
			a = s / n;
			s = s % n;
		}
		printf("%d\n", a%10);
	}
	return 0;
}


你可能感兴趣的:(hdu 2117 Just a Numble)