https://www.acmicpc.net/problem/1463
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 987654321
using namespace std;
// 1로 만들기
int solution(int a){
vector<int> arr(a+1, INF);
arr[a] = 0;
for(int i=0;i<a-1;i++){
int num = a-i;
if(arr[num] != INF){
int count = arr[num]+1;
if(num % 3 == 0)
arr[num/3] = min(arr[num/3], count);
if(num % 2 == 0)
arr[num/2] = min(arr[num/2], count);
arr[num-1] = min(arr[num-1], count);
}
}
return arr[1];
}
#include <cstdio>
using namespace std;
int i;
int Fast(int i)
{
if(i<=1) return 0;
int A = Fast(i/3) + i % 3 + 1;
int B = Fast(i/2) + i % 2 + 1;
return A < B ? A : B;
}
int main()
{
scanf("%d",&i);
printf("%d",Fast(i));
}