File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments