#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int de[3005];
int fd[5000000];
int main()
{
int a,b;
while(cin>>a>>b)
{
int temp=a;
int id=0;
memset(de,0,sizeof(de));
memset(fd,0,sizeof(fd));
printf("%d/%d = %d.",a,b,a/b);
a%=b;
int s;
while(1)
{
a*=10;
s=floor((double)a/b);
de[id]=s%10;
if(fd[a]!=0)
break;
fd[a]=++id;
a%=b;
}
for(int i=0;i<fd[a]-1;i++)
cout<<de[i];
cout<<"(";
int i;
for(i=fd[a]-1;i<id&&i<50;i++)
cout<<de[i];
if(i==50)
cout<<"...";
cout<<")"<<endl;
cout<<" "<<id-fd[a]+1<<" = number of digits in repeating cycle"<<endl<<endl;
}
return 0;
}
UVa202
最新推荐文章于 2019-08-03 19:38:12 发布