int G(x,y){return y?G(y,x%y):x;}
main(x,y,z,t,T,f){
	for(;scanf("%d%d",&x,&y),y;){
		y/=G(x,y);
		for(z=0;y%2==0;y/=2)z++;
		for(f=0;y%5==0;y/=5)f++;
		if(y==1)t=0;
		else for(t=1,T=10;(T-1)%y>0;T*=10)t++;
		printf("%d %d\n",z>f?z:f,t);
	}
	exit(0);
}