let factors : int -> (int * int) list = fun n ->
  let rec loop_i n i =
    if i * i > n then
      if n == 1 then [] else [(n, 1)]
    else if n mod i = 0 then
      let (n', c) = loop_j (n/i) i 1
      in
      (i, c) :: loop_i n' (i + 1)
    else
      loop_i n (i + 1)
  and loop_j n i j =
    if n mod i = 0 then
      loop_j (n / i) i (j + 1)
    else
      (n, j)
  in
  loop_i n 2

let rec print_int_list = function
    [] -> ()
  | (x :: xs) ->
     print_int x;
     print_char ' ';
     print_int_list xs

let rec merge = function
    ([], _) -> []
  | (_, []) -> []
  | ((x, cx)::xs, (y,cy)::ys) ->
     if x = y then
       x :: merge (xs, ys)
     else if x < y then
       merge (xs, (y,cy)::ys)
     else
       merge ((x,cx)::xs, ys)

let () =
  let (a, b) = Scanf.sscanf (input_line stdin) "%d %d" (fun a b -> (a, b)) in
  let facta = factors a in
  let factb = factors b in
  let ans_l  = 1 :: merge (facta, factb) in
  let ans = List.length ans_l
  in
  print_int ans;
  print_newline ()
