diff --git a/CmplxN/ChocolatesByNumbers.kt b/CmplxN/ChocolatesByNumbers.kt new file mode 100644 index 0000000..32f5bb6 --- /dev/null +++ b/CmplxN/ChocolatesByNumbers.kt @@ -0,0 +1,14 @@ +// you can also use imports, for example: +// import kotlin.math.* + +// you can write to stdout for debugging purposes, e.g. +// println("this is a debug message") + +fun solution(N: Int, M: Int): Int = N / gcd(N, M) + +tailrec fun gcd(a: Int, b: Int): Int { + return when (val r = a % b) { + 0 -> b + else -> gcd(b, r) + } +}