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
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>

using namespace std;

int main(int argc, char* argv[]) {
	string c;
	long long n = 10;

	cin >> c;
	int k = c.size() - 1;
	while (k--) n *= 10;

	long long r = 0;
	for (int i = 0; i < c.size(); i++)
		r = 10 * r + (int)(c[i] - '0');

	long long x = 0;
	long long y = 0;
	long long z = 1;

	k = 0;
	int m = n / 10;
	while (y < m) {
		x = z;
		z = y + z;
		swap(x, y);
		++k;
	}

	while (y != r) {
		x = z;
		z = y + z;
		swap(x, y);
		x %= n; y %= n; z %= n;
		++k;

		if (k > 10000000) {
			cout << "NIE" << endl;
			return 0;
		}
	}

	cout << k << endl;

	return 0;
}