diff --git a/storage/zeta/kt/completed/14856.kt b/storage/zeta/kt/completed/14856.kt new file mode 100644 index 0000000..91f6153 --- /dev/null +++ b/storage/zeta/kt/completed/14856.kt @@ -0,0 +1,56 @@ +import kotlin.math.* + + +val globalFibonacciSpace = Array(100, { i -> + if (i == 0 || i == 1) { + 1 + } else { + 0 + } +}) + +fun fib(i: Int): Long { + var spaceRef = globalFibonacciSpace[i]; + if (spaceRef == 0L) { + spaceRef = fib(i - 1) + fib(i - 2) + globalFibonacciSpace[i] = spaceRef + } + return spaceRef +} + + +fun getCreatingFibs(n: Long): List { + // 제켄도르프 정리에 의해 이 표현이 항상 존재함을 보증할 수 있음 + var curr = 90 + var now_counter = n + var cfibs = mutableListOf() + while (curr >= 1) { + if (fib(curr) <= now_counter) { + now_counter -= fib(curr) + cfibs.add(fib(curr)) + if (now_counter == 0L) { + break; + } + curr--; + } + + curr--; + } + + return cfibs + +} + +fun main() { + val n = readln().trim().toLong() + + run { + val t = getCreatingFibs(n) + println(t.size) + t + + }.reversed().forEach { i -> + print("$i ") + } + println() +} \ No newline at end of file