Scanf.scanf "%d %d" (fun n m ->
    let rec loop i acc =
        if i * i > m then acc else
            if m mod i <> 0 then loop (i + 1) acc else
            let acc = if m / i >= n then max acc i       else acc in
            let acc = if i     >= n then max acc (m / i) else acc in
            loop (i + 1) acc
    in
    loop 1 0 |> Printf.printf "%d\n"
)