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
#include <iostream>
#include <string>
using namespace std;

int main() {
	std::string input, s1 = "0", s2 = "1", k = "1", end = "1";
	bool flaga = false;
	short t;
	int i;
	cin >> input;
	if (input == s1) cout << 0;
	else if (input == s2) cout << 1;
	else
	{
		for (i = 0; i < 100; i++)
		{
			end = end + "0";
		}
		while(k != end)
		{
			flaga = false;
			for(i = s2.length() - 1; i >= 0; i--)
			{
				if(flaga) t = 1;
				else t = 0;
				t += ((short)s2[i] - 48) + ((short)s1[i] - 48);
				flaga = t > 9;
				s1[i] = s2[i];
				s2[i] = (char)((t % 10) + 48);
			}
			if (flaga && s2.length() < input.length())
			{
				s2 = "1" + s2;
				s1 = "0" + s1;
			}
			//cout << s2;
			flaga = false;
			i = k.length() - 1;
			do
			{
				t = ((short)k[i] - 48) + 1;
				flaga = t > 9;
				k[i] = (char)((t % 10) + 48);
				i--;
			}
			while (flaga && (i >= 0));
			if (flaga)
			{
				k = "1" + k;
			}
			//cout << " k: " << k << endl;
			if (s2 == input)
			{
				cout << k;
				return 0;
			}
		}
		cout << "NIE";
	}
	return 0;
}