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
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

LL MOD = 1e18;

struct matrix
{
	LL a, b, c, d;
};

LL mul(LL a, LL b)
{
	//assert(a >= 0 && b >= 0);
	if(a < b) swap(a,b);
	if(!b) return 0;
	if(b&1) return (a + mul(a,b-1))%MOD;
	LL res = mul(a,b/2);

	return (res + res) % MOD;
}

matrix mul(const matrix &a, const matrix &b)
{
	matrix p;
	p.a = (mul(a.a,b.a) + mul(a.b,b.c)) % MOD;
	p.b = (mul(a.a,b.b) + mul(a.b,b.d)) % MOD;
	p.c = (mul(a.c,b.a) + mul(a.d,b.c)) % MOD;
	p.d = (mul(a.c,b.b) + mul(a.d,b.d)) % MOD;

	return p;
}

matrix pow(matrix a, LL b)
{
	matrix p;
	p.a = p.d = 1;
	p.b = p.c = 0;
	while(b)
	{
		if(b & 1)
			p = mul(p,a);
		a = mul(a,a);
		b /= 2;
	}

	return p;
}

char s[20];

int main()
{
	// printf("%lld\n", mul(70, 60));
	// printf("%lld\n", mul(10345, 71598));
	matrix f;
	f.a = f.b = f.c = 1;
	f.d = 0;
	/*printf("%lld\n", pow(f,0).c);
	printf("%lld\n", pow(f,1).c);
	printf("%lld\n", pow(f,2).c);
	printf("%lld\n", pow(f,3).c);
	printf("%lld\n", pow(f,4).c);
	printf("%lld\n", pow(f,5).c);
	printf("%lld\n", pow(f,6).c);
	printf("%lld\n", pow(f,7).c);
	printf("%lld\n", pow(f,8).c);
	printf("%lld\n", pow(f,9).c);
	printf("%lld\n", pow(f,10).c);
	printf("%lld\n", pow(f,155).c);
	printf("%lld\n", pow(f,MOD).c);*/
	
	scanf("%s", s);
	int n = strlen(s);
	LL l = atoll(s);

	int fib0 = 0, fib1 = 1;

	bool exists = 0;

	int n1 = min(n,5);
	int MOD1 = 10;
	FORQ(i,2,n1) MOD1 *= 10;

	FOR(i,2,150000)
	{
		fib0 = (fib1+fib0) % MOD1;
		if(fib0 == l%MOD1)
		{
			exists = 1;
			break;
		}
		swap(fib0,fib1);
	}

	if(!exists)
	{
		printf("NIE\n");
		return 0;
	}
	
	fib0 = 0; fib1 = 1;
	
	if(n <= 5)
	{
		int MODR = 10;
		FORQ(i,2,n) MODR *= 10;
		if(fib0 == l)
		{
			printf("0\n");
			return 0;
		}
		if(fib1 == l)
		{
			printf("1\n");
			return 0;
		}
		int cnt = 2;
		while(true)
		{
			fib0 = (fib0 + fib1)%MODR;
			if(fib0 == l)
			{
				printf("%d\n", cnt);
				return 0;
			}
			cnt++;
			swap(fib0,fib1);
		}
	}

	// n > 5
	LL MODR = 100000;
	LL range = 150000;
	vector < LL > V;
	LL lookFor = l % MODR;
	if(fib0 == lookFor) V.PB(0);
	if(fib1 == lookFor) V.PB(1);
	FOR(i,2,range)
	{
		fib0 = (fib0+fib1) % MODR;
		if(fib0 == lookFor) V.PB(i);
		swap(fib0,fib1);
	}

	FORQ(i,6,n)
	{
		LL prev = range;
		range *= 10;
		MODR *= 10;
		lookFor = l % MODR;
		vector < LL > PV = V;
		V.clear();
		LL cnt = 0;
		while(cnt < range)
		{
			REP(j,(int)PV.size())
			{
				LL fib = pow(f,cnt+PV[j]).c % MODR;
				if(fib == lookFor)
				{
					if(fib == l)
					{
						printf("%lld\n", cnt+PV[j]);
						return 0;
					}
					V.PB(cnt+PV[j]);
				}
			}
			cnt += prev;
		}
	}

	return 0;
}