/*
Dreams never shine!
It's you that shine while chasing your dreams :)
JAYO!!
*/#include<iostream>#include<map>#include<string>#include<cassert>usingnamespace std;constint MAXN =3000+5;
map<int,int> Pos;// 记录被除数(n * 10), 及其对应的位置voidsolve(int n,constint d, string& ans,int& r){// n 余数, d 除数, ans 循环节, r 循环节长度assert(n % d && n < d);
ans =".";
Pos.clear();while(true){
n *=10;// 被除数int p = Pos[n];// 寻找是否已经储存被除数if(p ==0) Pos[n]= ans.size();// 没找到,就储存起来(记录下<被除数 * 10, 和在ans中的插入位置)else{
r = ans.size()- p;// 找到循环节(ans字符串当前长度,减去n第一次出现时在ans中的位置)if(r >50){
ans.erase(p +50);// 删除 p + 50 位之后的数(保留50位的循环节)
ans +="...";}
ans.insert(p,"(");// 循环节前插入 (
ans +=')';// 循环节后加上)break;}if(n < d){// continue后,再补0(n * 10, 补的0不够)
ans +='0';continue;// 补0}int div = n / d;int mod = n % d;
ans +=(char)(div +'0');
n = mod;if(n ==0){
ans +="(0)";
r =1;break;}}}intmain(){int a, b;while(scanf("%d%d",&a,&b)==2){
string ans =".(0)";int r =1;if(a % b)solve(a % b, b, ans, r);printf("%d/%d = %d%s\n", a, b, a / b, ans.c_str());printf(" %d = number of digits in repeating cycle\n\n", r);// 前面有三个空格}return0;}