Skip to content

Commit f53ccf8

Browse files
committed
CT_361
1 parent c13c104 commit f53ccf8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package B3;
2+
3+
import java.io.*;
4+
5+
public class Boj_16561_3의배수 {
6+
private static int n, cnt;
7+
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
12+
n = Integer.parseInt(br.readLine());
13+
cnt = 0;
14+
15+
permutation(0, 0);
16+
17+
bw.write(Integer.toString(cnt));
18+
bw.flush();
19+
}
20+
21+
private static void permutation(int depth, int sum) {
22+
if (depth == 3) {
23+
if (sum == n) cnt++;
24+
return;
25+
}
26+
27+
for (int i = 3; i <= n - 3 * (2 - depth); i += 3) {
28+
if (sum + i > n) break;
29+
permutation(depth + 1, sum + i);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)