#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; typedef Long long LL; #define The CLR (x , Y) memset ((×), (y),sizeof((x))) #define for (x, Y, z) for ( int.) = (y);(x) < (*); + + (x)) #define FORD ( x, Y, z) for(int.) = (y);(x) >= (z);--(x)) #define FOR2 ( x, Y, z) for((×) = (y);(x) < (z); + + (x) )#define FORD2 ( x, Y, z) for((>=) = (y);(x) (z);--(x) ) const int MAXN = + +; int N,ARR[MAXN * 2]; Arr saves the index that has occurred int dfs (int cur,int curd,const int & maxd) { if (curd = = Maxd) return arr[cur-1] = = N; //The current value can be up to square (1<< (Maxd-curd)) times, after calculating so many times, is less than n if (arr[cur-1] * 1<< (Maxd-curd) < n) return 0; //Enumerate indices that have occurred FORD (i,cur-1,0) { //Generate new value, go to next layer Arr[cur] = arr[cur-1] + arr[i]; if (DFS (cur + 1,curd + 1, maxd)) return 1;Arr[cur] = arr[cur-1]-arr[i]; if (DFS (cur + 1,curd + 1, maxd)) return 1; } return 0;}int init () { int tmp = n,cnt = 0;While (tmp > 1) {tmp/= 2;++cnt; } return cnt;}int Main () { //freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout); while (~scanf ("%d", &n) && N) {For (int i = init ();; ++i) {arr[0] = 1; if(Dfs (1,0,i)) {printf ("%d\n", i); break; } } } return 0;} |