#include <iostream> #include <cstdlib> #include <climits> using namespace std; const int M=10000; bool Vis[M+1] ; int F[M+1] ; void update (int &x, int y) { if (y<x) x=y; } int main () { int n; cin >> n; for (int i = 0; i <=M; i++) F[i]= INT_MAX; ___(1)___; int r=0; while (___(2)___) { r++; int x=0; for (int i = 1; i <= M; i++) if (___(3)___) x=i; Vis[x]=1; for (int i = 1; i <= M; i++) if (___(4)___) { int t=F[i] +F[x] ; if (i+x <=M) update (F[i+x] ,t) ; if (i!=x) update (F[abs (i-x)] ,t) ; if (i%x==0) update (F[i/x] ,t) ; if (x%i==0) update (F[x/i] ,t) ; } } cout <<F[n] << endl; return 0; }