问题描述
我们知道,整数做除法时,有时得到有限小数,有时得到无限循环小数。
如果我们把有限小数的末尾加上无限多个0,它们就有了统一的形式。
本题的任务是:在上面的约定下,求整数除法小数点后的第n位开始的3位数。
输入格式
一行三个整数:a b n,用空格分开。a是被除数,b是除数,n是所求的小数后位置(0<a,b,n<1000000000)
输出格式
一行3位数字,表示:a除以b,小数后第n位开始的3位数字。
样例输入
1 8 1
样例输出
125
样例输入
1 8 3
样例输出
500
样例输入
282866 999000 6
样例输出
914
注意:x~y为小数的循环节的条件是 在x,y两个位置作除法运算时得到的余数相等,而不是除数相等
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
static int s[];
static int vis[];
static int l;
static Map<Integer,Integer> ma;
public static Integer div(int a , int b) {
l = 1;
while(true) {
a = a%b;
if(ma.containsKey(new Integer(a%b))) {
return ma.get(new Integer(a%b));
}else {
ma.put(new Integer(a%b), new Integer(l));
}
a *= 10;
int temp = (int)a/(int)b;
s[l++] = temp;
// System.out.println(l);
// System.out.println(temp);
a = a % b;
}
}
public static void out(int n , int up , int cir) {
if(n < up) System.out.print(s[n]);
else System.out.print(s[(n-up)%cir+up]);
}
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
s = new int[1111111];
vis = new int[111111];
ma = new HashMap<Integer,Integer>();
int a = scan.nextInt();
int b = scan.nextInt();
int n = scan.nextInt();
int up = div(a,b) ;
// System.out.println(cir);
int cir = l-up;
// System.out.println(cir);
out(n,up,cir);out(n+1,up,cir);out(n+2,up,cir);
}
}