class Proc { public func proc() { let inpt = readLine()!.split(separator: " ").map{ Int64($0)! } let ans = getAns(bunsi: inpt[0], bunbo: inpt[1]) print(ans) } public func getAns(bunsi:Int64, bunbo:Int64)->Int64 { if bunbo == 1 { return bunsi - 1 } if bunbo == bunsi { return 0 } if bunsi > bunbo { if bunsi % bunbo == 0 { return bunsi / bunbo - 1 } else { return self.getAns(bunsi:bunsi % bunbo, bunbo:bunbo) + bunsi / bunbo } } else { return self.getAns(bunsi:bunbo, bunbo:bunsi) + 1 } } } Proc().proc()