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
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include <bits/stdc++.h>

using namespace std;

const unsigned long long INF = 1e9;
const unsigned long long MOD = INF * INF;

int tab[20] = {4, 6, 10, 12, 14, 18, 20, 22, 26, 28, 30};
int tab2[10] = {4, 6, 10, 12, 14};
int tab3[5] = {4, 6};
unsigned long long konwe[200];
vector <unsigned long long> cykl, cykl2;
unsigned long long dl[30];

unsigned long long konwertuj(string s)
{
    unsigned long long wyn = 0;
    unsigned long long pod = 1;
    
    for(int i = int(s.size()) - 1; i >= 0; i--)
      {
          wyn += pod * (unsigned long long)(s[i] - '0');
          konwe[i] = wyn;
          pod *= 10;
      }
    
    return wyn;
}

unsigned long long mno(unsigned long long a, unsigned long long b)
{
    unsigned long long wyn = 0;
    
    while(b > 0)
      {
          if((b & 1) == 1)
            wyn += a;
          
          wyn %= MOD;
          a += a;
          a %= MOD;
          b >>= 1;
      }
    
    return wyn;
}

void mnoz(unsigned long long* a, unsigned long long* b, unsigned long long* c)
{
    unsigned long long d[4];
    
    d[0] = (mno(a[0], b[0]) % MOD) + (mno(a[1], b[2]) % MOD);
    d[0] %= MOD;
    d[1] = (mno(a[0], b[1]) % MOD) + (mno(a[1], b[3]) % MOD);
    d[1] %= MOD;
    d[2] = (mno(a[2], b[0]) % MOD) + (mno(a[3], b[2]) % MOD);
    d[2] %= MOD;
    d[3] = (mno(a[2], b[1]) % MOD) + (mno(a[3], b[3]) % MOD);
    d[3] %= MOD;
    
    c[0] = d[0];
    c[1] = d[1];
    c[2] = d[2];
    c[3] = d[3];
}

unsigned long long fib(unsigned long long a)
{
    unsigned long long wyn[4], pod[4];
    
    wyn[0] = 1;
    wyn[1] = 1;
    wyn[2] = 1;
    wyn[3] = 0;
    
    pod[0] = 1;
    pod[1] = 1;
    pod[2] = 1;
    pod[3] = 0;
    
    while(a > 0)
      {
          if((a & 1) == 1)
            mnoz(wyn, pod, wyn);
          
          mnoz(pod, pod, pod);
          a >>= 1;
      }
    
    return wyn[3];
}

int main()
{
    dl[1] = 60;
    dl[2] = 300;
    dl[3] = 1500;
    
    for(int i = 4; i <= 18; i++)
      {
          dl[i] = dl[i - 1] * 10ll;
      }
    
    string s;
    
    cin>>s;
    
    unsigned long long n = konwertuj(s);
    
    /*if(n == 0)
      {
          puts("1500000000000000000000");
          return 0;
      }*/
    
    if(s.size() >= 5)
      {
        for(int i = 0; i < 11; i++)
          {
              if(tab[i] == n % 32)
                {
                    puts("NIE");
                    return 0;
                }
          }
      }
    
    else if(s.size() == 4)
      {
          for(int i = 0; i < 5; i++)
          {
              if(tab2[i] == n % 16)
                {
                    puts("NIE");
                    return 0;
                }
          }
      }
    
    else if(s.size() == 3)
      {
          for(int i = 0; i < 2; i++)
          {
              if(tab3[i] == n % 8)
                {
                    puts("NIE");
                    return 0;
                }
          }
      }
    
    bool czy = true;
    unsigned long long num = 0;
    
    while(czy)
      {
          if(fib(num) % 10 == s[s.size() - 1] - '0')
            {
                cykl.push_back(num);
            }
          
          num++;
          
          if(cykl.size() > 1)
            {
                if(cykl[0] + 60 == cykl.back())
                  czy = false;
            }
      }
    
    cykl.pop_back();
    unsigned long long mod = 10;
    int dl_cyklu = 1;
    
    for(int i = int(s.size()) - 2; i >= 0; i--)
      {
          mod *= 10;
          czy = true;
          num = 0;
          
          while(czy)
            {
                if(fib(cykl[num % cykl.size()] + (dl[dl_cyklu] * (num / cykl.size()))) % mod == konwe[i])
                  {
                      cykl2.push_back(cykl[num % cykl.size()] + (dl[dl_cyklu] * (num / cykl.size())));
                      //cout<<cykl[num % cykl.size()] + (dl[dl_cyklu] * (num / cykl.size()))<<endl;
                  }
                
              //  cout<<cykl[num % cykl.size()] + (dl[dl_cyklu] * (num / cykl.size()))<<endl;
                //system("pause");
                num++;
                
                if((cykl2.size() > 0) && (i == 0))
                  {
                      cykl[0] = cykl2[0];
                      break;
                  }
                
                if(cykl2.size() > 1)
                  {
                      if(cykl2[0] + dl[dl_cyklu + 1] == cykl2.back())
                        czy = false;
                  }
            }
          
          cykl2.pop_back();
          dl_cyklu++;
          
          cykl = cykl2;
          cykl2.clear();
      }
    
    cout<<"1500000000000000000000";
    cout<<cykl[0]<<endl;
    
   // system("pause");
    return 0;
}