#include <iostream>
#include <cmath>
#include <string>
using namespace std;
long long a = 0, b = 1, c = 1, sum;
long long cnt = 2; // 1, 1 już są
string tail, str_c;
long long modulo;
int padding;
int main()
{
ios_base::sync_with_stdio(false);
cin >> tail;
modulo = static_cast<long long>(pow(10, tail.length()) + 0.5);
//clog << modulo << endl;
while (true)
{
sum = (b + c) % modulo;
a = b;
b = c;
c = sum;
++cnt;
//cout << c << endl;
if (cnt > 10 && a == 2 && b == 3 && c == 5)
{
cout << "NIE\n";
//cout << c;
break;
}
str_c = to_string(c);
//clog << str_c << endl;
padding = tail.length() - str_c.length();
if (padding != 0) str_c = string(padding, '0') + str_c;
//clog << "padding " << padding << endl;
//clog << str_c << endl;
if (str_c == tail)
{
cout << cnt << endl;
break;
}
}
return 0;
}
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 | #include <iostream> #include <cmath> #include <string> using namespace std; long long a = 0, b = 1, c = 1, sum; long long cnt = 2; // 1, 1 już są string tail, str_c; long long modulo; int padding; int main() { ios_base::sync_with_stdio(false); cin >> tail; modulo = static_cast<long long>(pow(10, tail.length()) + 0.5); //clog << modulo << endl; while (true) { sum = (b + c) % modulo; a = b; b = c; c = sum; ++cnt; //cout << c << endl; if (cnt > 10 && a == 2 && b == 3 && c == 5) { cout << "NIE\n"; //cout << c; break; } str_c = to_string(c); //clog << str_c << endl; padding = tail.length() - str_c.length(); if (padding != 0) str_c = string(padding, '0') + str_c; //clog << "padding " << padding << endl; //clog << str_c << endl; if (str_c == tail) { cout << cnt << endl; break; } } return 0; } |
English