#include <iostream>
#include <string>
#include <math.h>
using namespace std;
string s;
long long suma = 0;
int mod;
unsigned long long l = 10000000000000000000;
long double tab[20]={0,0,60,300,1500,15000,150000,1500000,15000000,150000000,1500000000,15000000000,150000000000,
1500000000000,15000000000000,150000000000000,1500000000000000,15000000000000000,150000000000000000,1500000000000000000};
void read()
{
cin >> s;
int pot=1;
for(int i = s.size()-1; i>=0; i--)
{
suma+=((int)s[i]-48)*pot;
pot*=10;
}
while(suma<pot)
{
pot/=10;
}
mod = pot*10;
}
unsigned long long fib()
{
unsigned long long a=0,b=1,c;
int pom = tab[(int)(floor(log10(mod))+1)];
for(double i = 2; i <= 10000000 && i<= pom ;i++)
{
c = a+b;
if(c%mod==suma)
return i;
// cout << c%mod << endl;
a = b%l;
b = c%l;
}
return 0;
}
int main()
{
ios_base::sync_with_stdio(0);
read();
if(suma==0)
cout << "0";
unsigned long long wynik = fib();
// cout << tab[19] << endl;
if(suma!=0 && wynik!=0)
cout << wynik;
else
cout << "NIE";
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 56 57 | #include <iostream> #include <string> #include <math.h> using namespace std; string s; long long suma = 0; int mod; unsigned long long l = 10000000000000000000; long double tab[20]={0,0,60,300,1500,15000,150000,1500000,15000000,150000000,1500000000,15000000000,150000000000, 1500000000000,15000000000000,150000000000000,1500000000000000,15000000000000000,150000000000000000,1500000000000000000}; void read() { cin >> s; int pot=1; for(int i = s.size()-1; i>=0; i--) { suma+=((int)s[i]-48)*pot; pot*=10; } while(suma<pot) { pot/=10; } mod = pot*10; } unsigned long long fib() { unsigned long long a=0,b=1,c; int pom = tab[(int)(floor(log10(mod))+1)]; for(double i = 2; i <= 10000000 && i<= pom ;i++) { c = a+b; if(c%mod==suma) return i; // cout << c%mod << endl; a = b%l; b = c%l; } return 0; } int main() { ios_base::sync_with_stdio(0); read(); if(suma==0) cout << "0"; unsigned long long wynik = fib(); // cout << tab[19] << endl; if(suma!=0 && wynik!=0) cout << wynik; else cout << "NIE"; return 0; } |
English