题目链接
点此跳转
代码
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#define LL long long
#define mem(a, b) memset(a, b, sizeof a)
#define lowbit(x) (-x&x)
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define endl '\n'
using namespace std;
int n;
vector<int> A, B, C, D, E;
vector<int> add(vector<int> &A, vector<int> &B, vector<int> &C, vector<int> &D) {
int la = A.size(), lb = B.size(), lc = C.size(), ld = D.size();
vector<int> R;
for (int i = 0, t = 0; i < la || i < lb || i < lc || i < ld || t; i ++ ) {
t += (i < la ? A[i] : 0) + (i < lb ? B[i] : 0) + (i < lc ? C[i] : 0)
+ (i < ld ? D[i] : 0);
R.push_back(t % 10);
t /= 10;
}
return R;
}
int main() {
IOS;
while (cin >> n) {
A.clear(), B.clear(), C.clear(), D.clear(), E.clear();
A.push_back(1), B.push_back(1);
C.push_back(1), D.push_back(1);
E.push_back(1);
for (int i = 5; i <= n; i ++ ) {
E = add(A, B, C, D);
A = B, B = C, C = D, D = E;
}
reverse(E.begin(), E.end());
for (int t : E) cout << t;
cout << endl;
}
return 0;
}