#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(void){
string wzr,a,b,c;
int poprawne=0;
bool istnieje=false;
int j,tmp,reszt=0;
unsigned long long i,k=1;
a.resize(18,0);
b.resize(18,0);
c.resize(18,0);
cin>>wzr;
for(i=0;i<wzr.size();i++)wzr[i]-=48;
while(wzr[0]==0) wzr.erase(0,1); //usuwamy zera wiodace
if(wzr.size()>=3) {
for(i=0;i<wzr.size()-1;i++) k*=10;
k*=15;
}
else k=10000;
for(i=0;i<18;i++){ //zerowanie liczb
//printf("|");
a[i]=0;
if(i!=17)b[i]=0;
else b[i]=1;
c[i]=0;
}
for(i=0;i<k;i++){
for(j=0;j<18;j++) c[j]=0;
reszt=0;
for(j=17;j>=0;j--){
tmp=a[j]+b[j]+reszt;
//printf("%d+%d+%d=%d\n",a[j]+48,b[j]+48,reszt,tmp);
reszt=tmp/10;
tmp%=10;
c[j]=tmp;
}
poprawne=0;
for(j=wzr.size()-1;j>=0;j--){
if(wzr[j]==c[18-wzr.size()+j]) poprawne++;
}
if(poprawne==wzr.size()) {istnieje=true; break;}
a=b;
b=c;
}
if(istnieje){
//for(i=0;i<18;i++)c[i]+=48;
//while(c[0]=='0') c.erase(0,1);
//cout<<c<<"\n";
cout<<i+2;
}
else 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 | #include <stdio.h> #include <iostream> #include <string> using namespace std; int main(void){ string wzr,a,b,c; int poprawne=0; bool istnieje=false; int j,tmp,reszt=0; unsigned long long i,k=1; a.resize(18,0); b.resize(18,0); c.resize(18,0); cin>>wzr; for(i=0;i<wzr.size();i++)wzr[i]-=48; while(wzr[0]==0) wzr.erase(0,1); //usuwamy zera wiodace if(wzr.size()>=3) { for(i=0;i<wzr.size()-1;i++) k*=10; k*=15; } else k=10000; for(i=0;i<18;i++){ //zerowanie liczb //printf("|"); a[i]=0; if(i!=17)b[i]=0; else b[i]=1; c[i]=0; } for(i=0;i<k;i++){ for(j=0;j<18;j++) c[j]=0; reszt=0; for(j=17;j>=0;j--){ tmp=a[j]+b[j]+reszt; //printf("%d+%d+%d=%d\n",a[j]+48,b[j]+48,reszt,tmp); reszt=tmp/10; tmp%=10; c[j]=tmp; } poprawne=0; for(j=wzr.size()-1;j>=0;j--){ if(wzr[j]==c[18-wzr.size()+j]) poprawne++; } if(poprawne==wzr.size()) {istnieje=true; break;} a=b; b=c; } if(istnieje){ //for(i=0;i<18;i++)c[i]+=48; //while(c[0]=='0') c.erase(0,1); //cout<<c<<"\n"; cout<<i+2; } else printf("NIE"); return 0; } |
English