-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddWith123.java
40 lines (29 loc) · 933 Bytes
/
AddWith123.java
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class AddWith123 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(br.readLine());
for(int i = 0; i < num; i++) {
int number = Integer.parseInt(br.readLine());
System.out.println(getResult(number, 0));
}
}
public static int getResult(int n, int sum) {
int result = 0;
if(n == sum) {
return 1;
}
if(n < sum){
return 0;
}
if(n > sum) {
int value1 = getResult(n, sum + 1);
int value2 = getResult(n, sum + 2);
int value3 = getResult(n, sum + 3);
result += (value1 + value2 + value3);
}
return result;
}
}