#include<iostream> #include<algorithm> #include<string> usingnamespace std; int a[5003][5003];//用二维数组,因为i表示第几个数,j表示那个数的值 //这是高精度加法通用写法 int len = 1; voidadd(int m){
int c = 0;//表示进位 for (int i = 1; i <= len; i++) { a[m][i] += a[m - 1][i] + a[m - 2][i] + c; c = a[m][i] / 10; a[m][i] = a[m][i] % 10; if (c > 0) { len++; } }
while (len > 0 && a[m][len] == 0)//去除前导零 { len--; } } intmain(){ int n; cin >> n; //初始化两个值 a[1][1] = 1; a[2][1] = 2; for (int i = 3; i <= n; i++) { add(i); } //反向输出值 for (int i = len; i >= 1; i--) { cout << a[n][i]; } return0; }