#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;
long long pot_szybkie(long long a, unsigned int n)
{
long long w = 1;
while(n>0)
{
if (n%2 == 1)
w *= a;
a*= a;
n/=2;
}
return w;
}
int main()
{
long long n = 0;
long long warunek;
string liczba;
cin >> liczba;
int lg = liczba.size();
for(int i = 0; i < lg; ++i)
{
n += (liczba[i]-48) * pot_szybkie(10, lg-i-1);
}
int w;
if(lg==1)
{
warunek = 60;
}
else
{
warunek = 3 * pot_szybkie(10, lg);
if(lg>=3)
{
warunek /= 2;
}
}
w = pot_szybkie(10, lg);
long long a = 0, b = 1;
if((n==0)||(n==1))
{
printf("%lld", n);
return 0;
}
else
{
for(long long i = 2; i <= warunek+1; ++i)
{
long long temp = a+b;
temp %= w;
if(temp == n)
{
printf("%lld", i);
return 0;
}
temp = b;
b += a;
b %= w;
a = temp;
a %= w;
}
}
printf("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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #include <cstdio> #include <cmath> #include <cstdlib> #include <string> #include <iostream> using namespace std; long long pot_szybkie(long long a, unsigned int n) { long long w = 1; while(n>0) { if (n%2 == 1) w *= a; a*= a; n/=2; } return w; } int main() { long long n = 0; long long warunek; string liczba; cin >> liczba; int lg = liczba.size(); for(int i = 0; i < lg; ++i) { n += (liczba[i]-48) * pot_szybkie(10, lg-i-1); } int w; if(lg==1) { warunek = 60; } else { warunek = 3 * pot_szybkie(10, lg); if(lg>=3) { warunek /= 2; } } w = pot_szybkie(10, lg); long long a = 0, b = 1; if((n==0)||(n==1)) { printf("%lld", n); return 0; } else { for(long long i = 2; i <= warunek+1; ++i) { long long temp = a+b; temp %= w; if(temp == n) { printf("%lld", i); return 0; } temp = b; b += a; b %= w; a = temp; a %= w; } } printf("NIE"); return 0; } |
English