open System let ri () = stdin.ReadLine() |> int let ria () = stdin.ReadLine().Split() |> Array.map int let rec gcd a b = if a = 0L then b else gcd (b%a) a type Sol() = member this.Solve() = let [|N;D|] = ria() |> Array.map int64 N / (gcd N D) - 1L |> printfn "%d" () let mySol = new Sol() mySol.Solve()