본문 바로가기
알고리즘 & 자료구조/백준

백준 14651

by 신재권 2022. 1. 24.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main14651 {

	public static final int MOD = 1_000_000_009;
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine()); // 0,1,2 로 만들 N자리 3의 배수
		
		//D[i] = 0,1,2만 가지고 만든, i자리 3의 배수의 개수 
		long[] D = new long[33334];
		D[1] = 0;
		D[2] = 2; 
//		12 21 
		D[3] = 6;
//		102,111, 120, 201, 210, 222, 
		D[4] = 18;
//		1002, 1020, 1200, 2220, 2202, 2022, 1110, 1101, 1011,
//		2211, 2112, 2211, 1212, 2121, 2100, 2010, 2001, 1122,	
		
		for(int i=5; i<=N; i++) {
			D[i] = (D[i-1]*3) % MOD;
		}
		
		System.out.println(D[N]);
		

		
		
	}
	
	
	
}

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 15991  (0) 2022.01.26
백준 1633  (0) 2022.01.25
백준 16500  (0) 2022.01.23
백준 1106  (0) 2022.01.22
백준 15989  (0) 2022.01.21