| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
why PE123 908
.1354625550660792951541850220264317180616740088105
72687224669603524229074889867841409691629955947136
5638766519823788
The last 113 digits repeat forever.
#include<iostream>
using namespace std;
#define SIZE 1100
int res[SIZE];
int outlist[SIZE];
// pku 1140 Expanding Fractions
main()
{
int r;
int b,d;
int i,j;
int k;
int coutn;
while(1)
{
cin>>b>>d;
if(b == 0 && d == 0)
break;
r = b;
cout<<'.';
if( d == 0)
break;
i = 0;
k = 1;
while(r)
{
res[++i] = r;
for(j = i-1;j>=1;j--)
{
if(res[j] == r)
goto jmp;
}
coutn = (r*10)/d;
r = (r*10)%d;
f1:
// cout<<coutn;
outlist[k++] = coutn;
}
if(r == 0)
{
int pth = 1;
for(d = 1; d < k ; d++)
{
pth ++;
cout<<outlist[d];
if( pth % 50 == 0)
cout<<endl;
}
cout<<endl<<"This expansion terminates.\n";
}
else
{
jmp:
// cout<<endl;
// for(j = 1; j <= i ; j++)
// cout<<res[j]<<' ';
int pth = 1;
for(d = 1; d < k ; d++)
{
pth ++;
cout<<outlist[d];
if( pth % 50 == 0)
cout<<endl;
}
cout<<endl<<"The last "<<i - j<<" digits repeat forever.\n";
}
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator