```kotlin fun add(a: Int, b: Int): Int { var carry: Int var sum: Int do { sum = a xor b carry = (a and b) shl 1 a = sum b = carry } while (b != 0) return a }
fun subtract(a: Int, b: Int): Int { return add(a, add(b.inv(), 1)) }
fun multiply(a: Int, b: Int): Int { var result = 0 var shift = 0 var bCopy = b while (bCopy != 0) { if (bCopy and 1 == 1) { result = add(result, a shl shift) } shift++ bCopy = bCopy shr 1 } return result }
fun divide(a: Int, b: Int): Int { var dividend = a var divisor = b var quotient = 0 while (dividend >= divisor) { dividend = subtract(dividend, divisor) quotient = add(quotient, 1) } return quotient } ```