Just a Numble

来源:互联网 发布:python数据处理豆瓣 编辑:程序博客网 时间:2024/05/21 17:56

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 25 7123 123
 

Sample Output

508
想一样1除以一个数的过程,在纸上自己写一下,相当于先乘以10,用10除以一个数,然后在哪余数除以这个数,余数不够余数在乘以10.。。一次类推。就得出了下面的代码;
#include<iostream>#include<string.h>#include<stdio.h>#include<ctype.h>#include<algorithm>#include<stack>#include<queue>#include<set>#include<math.h>#include<vector>#include<deque>#include<list>using namespace std;int main(){    int n,m,i;    int z,a;    while(scanf("%d%d",&n,&m)!=EOF)    {        z=0;        a=10;        if(n!=1)            for(i=0; i<m; i++)            {                z=a/n;                a=a%n*10;            }        printf("%d\n",z);    }    return 0;}

0 0
原创粉丝点击