-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15988.java
More file actions
35 lines (25 loc) · 772 Bytes
/
15988.java
File metadata and controls
35 lines (25 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tcnum = sc.nextInt();
long[] d = new long[1000001];
d[1] = 1;
d[2] = d[1] + 1;
d[3] = d[1] + d[2] + 1;
for(int tcidx=0; tcidx<tcnum; tcidx++) {
int n = sc.nextInt();
if(d[n] != 0) {
System.out.println(d[n]);
continue;
}
for(int i=4; i<n+1; i++) {
if(d[i] != 0)
continue;
d[i] = d[i-1] % 1000000009 + d[i-2] % 1000000009 + d[i-3] % 1000000009;
d[i] %= 1000000009;
}
System.out.println(d[n]);
}
}
}