#include <bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define REP(i, a) FOR(i, 0, a)
#define TRACE(x) cout << #x << " " << x << endl
#define _ << " _ " <<

using namespace std;

#define task "b"

int erat[1000005];

ll pot(ll a, ll b, ll c){
  if (b == 0) return 1;
  ll r = pot((a*a)%c, b/2, c);
  if (b&1) r = (r*a)%c;
  return r;
}

int gcd(int a, int b){
  while (b) a %= b, swap(a, b);
  return a;
}

int main(){

  FOR(i,2,1000005)
    if (!erat[i])
      for (int j = i; j < 1000005; j += i)
	erat[j] = i;

  while (true){
    int a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) return 0;
    int g = gcd(a, b);
    a /= g, b /= g;
    int t = 0, u = 0;
    while (b % 2 == 0) ++t, b /= 2;
    while (b % 5 == 0) ++u, b /= 5;
    cout << max(t, u) << " ";

    int bb = b, phi = 1;
    while (bb != 1){
      int p = erat[bb];
      bb /= p;
      phi *= p-1;
      while (erat[bb] == p) phi *= p, bb /= p;
    }

    FOR(i,2,phi+1)
      while (phi%i == 0 && pot(10, phi/i, b) == 1) phi /= i;

    if (b == 1) phi = 0;
    cout << phi << endl;
  }
  
  return 0;
}