#include<bits/stdc++.h> using namespace std; typedef pair<long long int, long long int> ll; struct mac { ll m[2][2]; }; const long long int MOD=1e18,M=1e9; const ll ZERO=make_pair(0,0),JEDEN=make_pair(1,0); ll operator +(ll a, ll b) { ll wyn; wyn.first=(a.first+b.first)%M; wyn.second=(a.second+b.second+(a.first+b.first)/M)%M; return wyn; } ll operator *(ll a, ll b) //UWAGA { ll wyn; wyn.first=(b.first*a.first)%M; wyn.second=(((((b.first*a.first)/M)+ b.first*a.second)%M)+ b.second*a.first)%M; return wyn; } mac mmac(ll a, ll b, ll c, ll d) //a b { //c d mac wyn; wyn.m[0][0]=a; wyn.m[0][1]=b; wyn.m[1][0]=c; wyn.m[1][1]=d; return wyn; } mac operator *(mac a, mac b) { return mmac((a.m[0][0]*b.m[0][0])+(a.m[0][1]*b.m[1][0]), (a.m[0][0]*b.m[0][1])+(a.m[0][1]*b.m[1][1]), (a.m[1][0]*b.m[0][0])+(a.m[1][1]*b.m[1][0]), (a.m[1][0]*b.m[0][1])+(a.m[1][1]*b.m[1][1])); } long long int tz[19]; mac tp[109]; void Potega(long long int n) { int l=2; tp[0]=mmac(JEDEN,ZERO,ZERO,JEDEN); tp[1]=mmac(JEDEN,JEDEN,JEDEN,ZERO); for(long long int i=2;i<=n;i*=2) { tp[l]=tp[l-1]*tp[l-1]; //printf("%lld\n",tp[l].m[0][0].second*M+tp[l].m[0][0].first); ++l; } } long long int fib(long long int x) { int l=1; mac wyn=tp[0]; --x; while(x>0) { if(x%2) wyn=wyn*tp[l]; x>>=1; ++l; } return wyn.m[0][0].second*M+wyn.m[0][0].first; } int main() { int n; long long int ak,roz,pot; char tc[19]; list<long long int> lista; scanf("%s",tc); n=strlen(tc); tz[0]=1; tz[1]=60; tz[2]=300; tz[3]=1500; for(int i=4;i<=n;++i) tz[i]=tz[i-1]*10; Potega(tz[n]); lista.push_back(1); pot=1; for(int i=1;i<=n;++i) { roz=lista.size(); for(long long int j=0;j<roz;++j) { ak=lista.front(); lista.pop_front(); //printf("%d %lld\n",i,ak); for(long long int k=ak;k<=tz[i];k+=tz[i-1]) { //printf("%lld %lld %d\n",k,fib(k),tc[n-i]-'0'); if((fib(k)/pot)%10==tc[n-i]-'0') lista.push_back(k); //printf("%lld\n",lista.back());} } } pot*=10; } if(lista.empty()) printf("NIE"); else printf("15000000000000000000%lld",lista.front()); 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 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 | #include<bits/stdc++.h> using namespace std; typedef pair<long long int, long long int> ll; struct mac { ll m[2][2]; }; const long long int MOD=1e18,M=1e9; const ll ZERO=make_pair(0,0),JEDEN=make_pair(1,0); ll operator +(ll a, ll b) { ll wyn; wyn.first=(a.first+b.first)%M; wyn.second=(a.second+b.second+(a.first+b.first)/M)%M; return wyn; } ll operator *(ll a, ll b) //UWAGA { ll wyn; wyn.first=(b.first*a.first)%M; wyn.second=(((((b.first*a.first)/M)+ b.first*a.second)%M)+ b.second*a.first)%M; return wyn; } mac mmac(ll a, ll b, ll c, ll d) //a b { //c d mac wyn; wyn.m[0][0]=a; wyn.m[0][1]=b; wyn.m[1][0]=c; wyn.m[1][1]=d; return wyn; } mac operator *(mac a, mac b) { return mmac((a.m[0][0]*b.m[0][0])+(a.m[0][1]*b.m[1][0]), (a.m[0][0]*b.m[0][1])+(a.m[0][1]*b.m[1][1]), (a.m[1][0]*b.m[0][0])+(a.m[1][1]*b.m[1][0]), (a.m[1][0]*b.m[0][1])+(a.m[1][1]*b.m[1][1])); } long long int tz[19]; mac tp[109]; void Potega(long long int n) { int l=2; tp[0]=mmac(JEDEN,ZERO,ZERO,JEDEN); tp[1]=mmac(JEDEN,JEDEN,JEDEN,ZERO); for(long long int i=2;i<=n;i*=2) { tp[l]=tp[l-1]*tp[l-1]; //printf("%lld\n",tp[l].m[0][0].second*M+tp[l].m[0][0].first); ++l; } } long long int fib(long long int x) { int l=1; mac wyn=tp[0]; --x; while(x>0) { if(x%2) wyn=wyn*tp[l]; x>>=1; ++l; } return wyn.m[0][0].second*M+wyn.m[0][0].first; } int main() { int n; long long int ak,roz,pot; char tc[19]; list<long long int> lista; scanf("%s",tc); n=strlen(tc); tz[0]=1; tz[1]=60; tz[2]=300; tz[3]=1500; for(int i=4;i<=n;++i) tz[i]=tz[i-1]*10; Potega(tz[n]); lista.push_back(1); pot=1; for(int i=1;i<=n;++i) { roz=lista.size(); for(long long int j=0;j<roz;++j) { ak=lista.front(); lista.pop_front(); //printf("%d %lld\n",i,ak); for(long long int k=ak;k<=tz[i];k+=tz[i-1]) { //printf("%lld %lld %d\n",k,fib(k),tc[n-i]-'0'); if((fib(k)/pot)%10==tc[n-i]-'0') lista.push_back(k); //printf("%lld\n",lista.back());} } } pot*=10; } if(lista.empty()) printf("NIE"); else printf("15000000000000000000%lld",lista.front()); return 0; } |