백준 9461번(Java)

박은지·2025년 4월 3일
0

백준

목록 보기
52/89
post-thumbnail

import java.io.*;

public class Main {
	
	public static Long seq[] = new Long[101];
	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		seq[0] = 0L;
		seq[1] = 1L;
		seq[2] = 1L;
		seq[3] = 1L;
		
		int T = Integer.parseInt(br.readLine());

		while(T-- > 0) {
			sb.append(padovan(Integer.parseInt(br.readLine()))).append('\n');
		}
		System.out.println(sb);
	}
	
	public static long padovan(int N) {
		if(seq[N] == null) {
			seq[N] = padovan(N-2) + padovan(N-3);
		}
		return seq[N];
	}

}
profile
백엔드 개발자가 되고싶은 eunzi😊

0개의 댓글