-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem3_1.java
More file actions
42 lines (27 loc) Β· 849 Bytes
/
problem3_1.java
File metadata and controls
42 lines (27 loc) Β· 849 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
36
37
38
39
40
41
42
package basic.practice;
import java.util.Scanner;
public class problem3_1 {
static int N;
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int TestCase = Integer.parseInt(scan.nextLine());
for(int i = 0 ; i<TestCase;i++){
N = Integer.parseInt(scan.nextLine());
int[] array = new int[3];
array[0] = 1;
array[1] = 1;
array[2] = 2;
if(N<3){
System.out.println(array[N]);
continue;
}
for(int j =3;j<=N;j++){
int temp = array[0] + array[1] + array[2];
array[0] = array[1];
array[1] = array[2];
array[2] = temp;
}
System.out.println(array[2]);
}
}
}