模拟循环小数
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define N 100000
int save[N];
int rem[4000];
int main()
{
int n,m,z,re,nn,tmp,s,e,cas=1;
while(~scanf("%d%d",&n,&m)){
memset(rem,-1,sizeof(rem));
z=n/m;
nn=1;
re=n%m;
rem[re]=0;
re*=10;
while(1){
save[nn]=re/m;
re=re%m;
if(rem[re]!=-1){
s=rem[re]+1;
e=nn;
break;
}
rem[re]=nn++;
re*=10;
}
printf("%d/%d = %d.",n,m,z);
for(int i=1;i<s;i++) printf("%d",save[i]);
printf("(");
for(int i=s;i<=e&&i<=50;i++){
printf("%d",save[i]);
}
if(nn>50) printf("...");
printf(")\n");
printf(" %d = number of digits in repeating cycle\n\n",e-s+1);
cas++;
}
return 0;
}