program karuseles;
  const PR = 'KARUS.DAT';
        RZ = 'KARUS.REZ';

  procedure karusele (a, b: longint; var aplankyti, min_b: longint);

     function bdd (a, b: longint): longint;
        { randa a ir b bendr…j did‘iausi… dalikl }
     begin
       if a = 0
         then bdd := b
         else bdd := bdd (b mod a, a);
     end; { bdd }

  begin
    aplankyti := a div bdd(a, b);
    min_b := 20;
    while bdd (a, min_b) <> 1 do
      min_b := min_b + 1;
  end; { karusel‚ }

  var f: text;
      a, b, aplankyti, min_b: longint;
begin
  assign (f, PR);
  reset (f);
  readln (f, a, b);
  close (f);
  karusele (a, b, aplankyti, min_b);
  assign (f, RZ);
  rewrite (f);
  writeln (f, aplankyti);
  writeln (f, min_b);
  close (f);
end.
