#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int n,m;
while(cin>>n>>m)
{
int a=n/m,b=n%m;
int ans[5000]={a},cnt=0;
int p[5000]={};
p[b]=++cnt;
while(1)
{
b*=10;
ans[cnt]=b/m;
b=b%m;
if(p[b]) break;
p[b]=++cnt;
}
cout<<n<<"/"<<m<<" = ";
for(int i=0;i<=cnt&&i<p[b]+50;i++)
{
if(i==1) cout<<".";
if(i==p[b]) cout<<"(";
cout<<ans[i];
}
if(cnt>50) cout<<"...)"<<endl;
else cout<<")"<<endl;
cout<<" "<<cnt-p[b]+1<<" = number of digits in repeating cycle"<<endl<<endl;
}
}
UVa-202 - Repeating Decimals
最新推荐文章于 2022-01-04 17:22:29 发布