-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_1463
More file actions
44 lines (37 loc) ยท 1005 Bytes
/
BAEKJOON_1463
File metadata and controls
44 lines (37 loc) ยท 1005 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
43
44
import java.io.*;
import java.sql.Array;
import java.util.*;
public class Main {
static int[] d;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
d = new int[1000001];
int N = Integer.parseInt(br.readLine());
bw.write(String.valueOf(recursion(N)));
bw.flush();
bw.close();
}
public static int recursion(int N){
if(N==1){
return 0;
}
if(d[N]>0){
return d[N];
}
d[N] = recursion(N-1)+1;
if(N%3 ==0){
int temp = recursion(N/3)+1;
if(temp < d[N]){
d[N] =temp;
}
}
if(N%2 ==0){
int temp = recursion(N/2)+1;
if(temp < d[N]){
d[N] = temp;
}
}
return d[N];
}
}