let id x = x

let rec n_prime f x =
  let rec is_dividable l m =
    (m >= l * l) && ((x mod l = 0) || is_dividable (l + 1) m) in
  if is_dividable 2 (x - 1) then n_prime f (f x) else x

let _ =
  try
    while true do
      let x = Scanf.scanf "%d\n" id in
      Printf.printf "%d %d\n" (n_prime (fun i -> i - 1) (x - 1)) (n_prime (fun i -> i + 1) (x + 1))
    done
  with
    End_of_file -> ()