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
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <utility>
#include <fstream>
#include <cassert>

#define INF 999999999999999999LL
#define MOD 1000000007
#define MAX 5224025
#define ALL 50
#define DEBUG false

using namespace std;

int T[ALL];

int main()
{
	string str;
	cin >> str;

	int n = str.length();
	for (int i = n - 1; i >= 0; --i) {
		T[n - i - 1] = (int)str[i] - 48;
	}

	int current = 2, ans;
	long long first = 0, second = 1, pom;

	if (n == 1) {
		if (T[0] == 0) {
			printf("0");
			return 0;
		} else if(T[0] == 1) {
			printf("1");
			return 0;
		}
	}

	bool res = false;
	while (current < MAX && !res) {
		pom = first;
		first = second;
		second = pom + first;

		pom = second;
		int checked = 0;
		bool ok = true;
		while (pom != 0 && checked < n && ok) {
			int rest = pom % 10;
			if (T[checked] != rest)
				ok = false;

			pom -= rest;
			pom /= 10;
			checked++;
		}

		if (ok && checked < n)
			ok = false;

		if (ok) {
			res = true;
			ans = current;
		}

		first %= 1000000000000000000;
		second %= 1000000000000000000;
		current++;
	}

	if (res) {
		printf("%d", ans);
	}
	else
		printf("NIE");

	return 0;
}