문제 확인하기
2. 정답 코드 1 (Python, memory: 31120KB, time: 100ms)
def main():
n = int(input())
fib = [0] * 81
fib[0] = 4
fib[1] = 6
for i in range(2, n):
fib[i] = fib[i - 1] + fib[i - 2]
print(fib[n - 1])
if __name__ == "__main__":
main()
3. 정답 코드 2(Java, memory: KB, time: ms)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
long[] fib = new long[81];
fib[0] = 4;
fib[1] = 6;
for (int i = 2; i < n; i++) {
fib[i] = fib[i - 1] + fib[i - 2];
}
System.out.println(fib[n - 1]);
scanner.close();
}
}