#include <iostream> #include <vector> using namespace std; void f(int tab1[], int tab2[]){ int tab3[101]; int p1; for(int i=0;i<101;i++){ tab3[i]=0; } for(int i=100;i>=0;i--){ tab3[i]+=tab1[i]+tab2[i]; if(tab3[i]>9){ if(i>0)tab3[i-1]++; tab3[i]=tab3[i]%10; } tab1[i]=tab2[i]; tab2[i]=tab3[i]; } } void wypisz(int tab[]){ int p; for(int i=0;i<101;i++){ if(tab[i]!=0){ p=i; break; } } for(int i=p;i<101;i++){ cout<<tab[i]; } } int main() { int l1[101]; int l2[101]; int n; cin>>n; int d=0; int n2=n; while(n2!=0){ d++; n2/=10; } int tab[d]; n2=n; for(int i=d-1;i>=0;i--){ tab[i]=n2%10; n2/=10; } for(int i=0;i<101;i++){ l1[i]=0; l2[i]=0; } l1[100]=0; l2[100]=1; bool corect=true; while(l1[0]==0){ corect=true; for(int i=d-1;i>=0;i--){ if(tab[i]!=l2[100-((d-1)-i)])corect=false; } if(corect==true){ wypisz(l2); return 0; } f(l1,l2); } 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 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 | #include <iostream> #include <vector> using namespace std; void f(int tab1[], int tab2[]){ int tab3[101]; int p1; for(int i=0;i<101;i++){ tab3[i]=0; } for(int i=100;i>=0;i--){ tab3[i]+=tab1[i]+tab2[i]; if(tab3[i]>9){ if(i>0)tab3[i-1]++; tab3[i]=tab3[i]%10; } tab1[i]=tab2[i]; tab2[i]=tab3[i]; } } void wypisz(int tab[]){ int p; for(int i=0;i<101;i++){ if(tab[i]!=0){ p=i; break; } } for(int i=p;i<101;i++){ cout<<tab[i]; } } int main() { int l1[101]; int l2[101]; int n; cin>>n; int d=0; int n2=n; while(n2!=0){ d++; n2/=10; } int tab[d]; n2=n; for(int i=d-1;i>=0;i--){ tab[i]=n2%10; n2/=10; } for(int i=0;i<101;i++){ l1[i]=0; l2[i]=0; } l1[100]=0; l2[100]=1; bool corect=true; while(l1[0]==0){ corect=true; for(int i=d-1;i>=0;i--){ if(tab[i]!=l2[100-((d-1)-i)])corect=false; } if(corect==true){ wypisz(l2); return 0; } f(l1,l2); } cout<<"NIE"; return 0; } |