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
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <algorithm>

#ifdef PA_LOCAL
#include "../Common/common.h"
#else
#define init(...)
#define finalize()
#endif

using namespace std;

bool test(const char* rest_str, uint64_t& res)
{
	uint64_t n = strlen(rest_str);

	uint64_t rest;
	sscanf(rest_str, "%llu", &rest);

	uint64_t mod = 1llu;
	for (uint64_t i = 0; i < n; ++i)
	{
		mod *= 10llu;
	}

	uint64_t k = 1llu;
	uint64_t max_k = 15llu * (mod / 10llu);
	if (mod == 10llu)
	{
		max_k = 60llu;
	}
	else if (mod == 100llu)
	{
		max_k = 300llu;
	}
	
	uint64_t f_k_1 = 0;
	uint64_t f_k = 1;

	for (; k < max_k; ++k)
	{
		if (f_k >= mod && f_k % mod == rest)
		{
			break;
		}

		uint64_t new_f_k = f_k_1 + f_k % mod;
		f_k_1 = f_k;
		f_k = new_f_k;
	}

	res = k;
	return k < max_k;
}

int main(int argc, const char* argv[])
{
	init("example_fail");

	char rest_str[19] = { '\0' };
	scanf("%s", rest_str);
	int32_t n = strlen(rest_str);
	
	uint64_t res;
	for (int32_t i = n - 1; i >= 0; --i)
	{
		if (!test(rest_str + i, res))
		{
			printf("NIE\n");
			finalize();
			return 0;
		}
	}

	printf("%llu\n", res);
	finalize();
	return 0;
}