#include <iostream>
#include <string>
using namespace std;
bool zakoncz=0;
string fibonaczczi(string mniejsza, string wieksza)
{
if (mniejsza.length()<wieksza.length()) mniejsza.insert(0, "0");
for (int i=mniejsza.length()-1; i>=0; i--)
{
mniejsza[i]+=wieksza[i]-'0';
if (mniejsza[i]>'9')
{
mniejsza[i]-=10;
if (i>0) mniejsza[i-1]+=1;
else mniejsza.insert(0, "1");
}
}
return mniejsza;
}
int main()
{
string mniejsza, wieksza, szarlotka;
mniejsza=wieksza="1";
cin >> szarlotka;
if (szarlotka.length()==1)
{
if (szarlotka[0]=='0')
{
cout << "0"; return 0;
}
if (szarlotka[0]=='1')
{
cout << "1"; return 0;
}
}
int numer=2;
while(numer++ && numer<481)
{
mniejsza=fibonaczczi(mniejsza, wieksza);
swap (mniejsza, wieksza);
if (szarlotka.length()<=wieksza.length())
{
if (szarlotka==wieksza.substr(wieksza.length()-szarlotka.length(), szarlotka.length()))
{
cout << numer; return 0;
}
}
}
cout << "NIE";
}
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 <string> using namespace std; bool zakoncz=0; string fibonaczczi(string mniejsza, string wieksza) { if (mniejsza.length()<wieksza.length()) mniejsza.insert(0, "0"); for (int i=mniejsza.length()-1; i>=0; i--) { mniejsza[i]+=wieksza[i]-'0'; if (mniejsza[i]>'9') { mniejsza[i]-=10; if (i>0) mniejsza[i-1]+=1; else mniejsza.insert(0, "1"); } } return mniejsza; } int main() { string mniejsza, wieksza, szarlotka; mniejsza=wieksza="1"; cin >> szarlotka; if (szarlotka.length()==1) { if (szarlotka[0]=='0') { cout << "0"; return 0; } if (szarlotka[0]=='1') { cout << "1"; return 0; } } int numer=2; while(numer++ && numer<481) { mniejsza=fibonaczczi(mniejsza, wieksza); swap (mniejsza, wieksza); if (szarlotka.length()<=wieksza.length()) { if (szarlotka==wieksza.substr(wieksza.length()-szarlotka.length(), szarlotka.length())) { cout << numer; return 0; } } } cout << "NIE"; } |
English