Its a fibonicci series solution. I dont know why….But found that it shows the similiarity.
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 |
#include <iostream> #include <vector> using namespace std; int fib[2000][5000]; vector<int> vb[2001]; int main() { fib[0][0]=1; fib[1][0]=2; fib[2][0]=3; int c=0; for(int i=3;i<2000;i++) { for(int j=0;j<5000;j++) { int t=fib[i-1][j]+fib[i-2][j]+c; fib[i][j]=t%10; c=t/10; } } //cout<<fib[3][0]; vb[0].push_back(1); vb[1].push_back(2); vb[2].push_back(3); for(int i=3;i<2000;i++) { int f=0; for(int j=4999;j>=0;j--) { if(f) { vb[i].push_back(fib[i][j]); continue; } if(fib[i][j]) { vb[i].push_back(fib[i][j]); f=1; } } } int n; while(cin>>n) { for(int i=0;i<vb[n].size();i++) cout<<vb[n][i]; cout<<"\n"; } return 0; } |