package 第三章习题;
import java.util.Arrays;
import java.util.Scanner;
/*
* 输入整数a和b(0<=a<=3000,1<=b<=3000),
* 输出a/b的循环小数表示以及循环节长度。
例如,a=5,b=43,
小数表示为0.(116279069767441860465),循环字节长度为21
*/
//循环不一定是从小数点后一位数开始,可能从之后才开始循环
public class 习题3_08循环小数 {
final static int MAX = 3005;
static int cx[]=new int[MAX];
static int fs[]=new int[MAX];
public static void main(String[] args) {
int n, m, t, i;
int cou= 0;
Scanner in=new Scanner(System.in);
n=in.nextInt();
m=in.nextInt();
cou = 0;
Arrays.sort(cx);
Arrays.sort(fs);
System.out.print(n+"/"+m+"="+n/m+".");
t = n;
while(true)
{
t = t % m * 10;
fs[cou] = t / m;
for(i = 0; i < cou; ++i)
if(cx[i] == t) break;
if(i != cou) break;
cx[cou++] = t;
}
for(int q = 0; q < i;q++)
System.out.print(fs[q]);
System.out.print("(");
if(cou > 50)
{
for(int q = i; q < i+50; q++)
System.out.println(fs[q]);
System.out.print("...");
}
else
{
for(int q = i; q < cou; q++)
System.out.print(fs[q]);
}
System.out.println(")\n"+(cou-i)+"= number of digits in repeating cycle");
}
}
import java.util.Arrays;
import java.util.Scanner;
/*
* 输入整数a和b(0<=a<=3000,1<=b<=3000),
* 输出a/b的循环小数表示以及循环节长度。
例如,a=5,b=43,
小数表示为0.(116279069767441860465),循环字节长度为21
*/
//循环不一定是从小数点后一位数开始,可能从之后才开始循环
public class 习题3_08循环小数 {
final static int MAX = 3005;
static int cx[]=new int[MAX];
static int fs[]=new int[MAX];
public static void main(String[] args) {
int n, m, t, i;
int cou= 0;
Scanner in=new Scanner(System.in);
n=in.nextInt();
m=in.nextInt();
cou = 0;
Arrays.sort(cx);
Arrays.sort(fs);
System.out.print(n+"/"+m+"="+n/m+".");
t = n;
while(true)
{
t = t % m * 10;
fs[cou] = t / m;
for(i = 0; i < cou; ++i)
if(cx[i] == t) break;
if(i != cou) break;
cx[cou++] = t;
}
for(int q = 0; q < i;q++)
System.out.print(fs[q]);
System.out.print("(");
if(cou > 50)
{
for(int q = i; q < i+50; q++)
System.out.println(fs[q]);
System.out.print("...");
}
else
{
for(int q = i; q < cou; q++)
System.out.print(fs[q]);
}
System.out.println(")\n"+(cou-i)+"= number of digits in repeating cycle");
}
}