首页 > ACM题库 > HDU-杭电 > hdu 2117 Just a Numble-模拟-[解题报告]C++
2013
12-29

hdu 2117 Just a Numble-模拟-[解题报告]C++

Just a Numble

问题描述 :

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

输入:

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

输出:

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

样例输入:

4 2
5 7
123 123

样例输出:

5
0
8

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(n==1)
        printf("0\n");
        else
        {
            int temp=1;
            int u;
            while(m--)
            {
                temp*=10;
                u=temp/n;
                temp%=n;
            }
            printf("%d\n",u);
        }
    }
}

解题转自:http://blog.csdn.net/ronghuayang123/article/details/8631066