// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>
using namespace std;
// typedef
typedef __int64 LL;
//
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#define Z(a,b) ((a)<<(b))
#define Y(a,b) ((a)>>(b))
const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 1000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);
template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
if(x>y) return x;
return y;
}
template<class T> inline T TMIN(T x,T y)
{
if(x<y) return x;
return y;
}
template<class T> inline T MMAX(T x,T y,T z)
{
return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
return TMIN(TMIN(x,y),z);
}
template<class T> inline void SWAP(T &x,T &y)
{
T t = x;
x = y;
y = t;
}
// code begin
int s,x;
int rm[1001];
int stk[1001],top;
int main()
{
read;
write;
while(scanf("%d %d",&s,&x)==2)
{
if(s+x==0) break;
memset(rm,0,sizeof(rm));
s%=x;
top = 0;
int cnt = 0,f = 0;
rm[s] = ++cnt;
while(1)
{
s*=10;
stk[top++] = s/x;
s%=x;
if(s==0)
{
break;
}
if(rm[s])
{
f = ++cnt-rm[s];
break;
}
rm[s] = ++cnt;
}
printf(".");
cnt = 1;
for(int i=0;i<top;i++,cnt++)
{
if(cnt%50==0) printf("\n");
printf("%d",stk[i]);
}
printf("\n");
if(f)
printf("The last %d digits repeat forever.\n",f);
else
printf("This expansion terminates.\n");
}
return 0;
}