백준 1003번(Java)

박은지·2025년 3월 12일
0

백준

목록 보기
46/89
post-thumbnail

import java.io.*;
import java.util.*;

public class Main {
	static int zero;
	static int one;
	static int zeroPlusOne;

	public static void main(String[] args) throws IOException {
		StringBuilder sb = new StringBuilder();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int T = Integer.parseInt(br.readLine());
		
		for(int i=0; i<T; i++) {
			int N = Integer.parseInt(br.readLine());
			fibonacci(N);
			sb.append(zero).append(' ').append(one).append('\n');
		}
		System.out.println(sb);
	}
	
	public static void fibonacci(int N) {
		zero = 1;
		one = 0;
		zeroPlusOne = 1;
		
		for(int i=0; i<N; i++) {
			zero = one; // 0호출 횟수를 이전의 1호출 횟수로 변경
			one = zeroPlusOne; // 1호출 횟수를 이전의 0과 1호출 횟수의 합으로 변경
			zeroPlusOne = zero + one; // 0과 1호출의 합 계산
		}
	}
}
profile
백엔드 개발자가 되고싶은 eunzi😊

0개의 댓글