publicstaticvoidmain(String[] args)throws Exception { BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine()); out.write("" + makeItOne(n)); out.write("\n"); out.flush(); out.close(); in.close(); } publicstaticintmakeItOne(int n){ int[] table = newint[n + 1]; table[1] = 0; for (int i = 2; i <= n; i++) { table[i] = table[i - 1] + 1; if (i % 2 == 0 && table[i] > table[i / 2] + 1) { table[i] = table[n / 2] + 1; } elseif (i % 3 == 0 && table[i] > table[i / 3] + 1) { table[i] = table[n / 3] + 1; } } return table[n]; } //짧은 코드 publicstaticintmakeItOne2(int n){ int[] dp = newint[n + 1]; for (int i = 2; i <= n; i++) { dp[i] = Math.min(dp[i / 2] + (i % 2), dp[i / 3] + (i % 3)) + 1; } return dp[n]; } }