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

int main(void)
{
	long long pattern, mask;

	std::string patternString;
	std::cin >> patternString;

	mask = 10LL;
	for (unsigned int i=1; i<patternString.length(); i++)
	{
		mask *= 10LL;
	}
	pattern = std::stoll(patternString, NULL, 10);

	long long F[3] = {0LL, 1LL, 1LL};
	long long x;
	int i = 0;

	for (long long p = 0; p < 1000000000LL; p++)
	{
		for (long long q = 0; q < 1000000000LL; q++)
		{
			if ( p == 0 && q == 0 ) {
				x = 0;
			}
			else if ( p == 0 && q == 1 ) {
				x = 1;
			}
			else {
		
				x = ( F[(i-1+3)%3] + F[(i-2+3)%3] ) % mask;

				if ( x == 1 && F[(i-1+3)%3] == 1 && F[(i-2+3)%3] == 0 && !(p==0 && q==2) )
				{
					//new cycle
					std::cout << "NIE" << std::endl;
					return 0;
				}				
			}

			if (x == pattern) {
				if (p > 0) {
					std::cout << p ;
				}
				std::cout << q << std::endl;

				return 0;
			}

			F[i] = x;

			i = (i+1)%3;			

		}
	}
	std::cout << "NIE" << std::endl;

	return 0;
}