The title describes
the given number sequence 1, 1, 1, 3, 5, 9, 17, …, starting from item 4, each item is the sum of the first 3 items. Find
the last 4 digits of item 20190324.
code show as below:
#include <iostream>
using namespace std;
const int N = 20190334;
int a[N];
int main() {
a[1] = 1;
a[2] = 1;
a[3] = 1;
for (int i = 4; i <= 20190324; i++) {
a[i] = (a[i - 1] + a[i - 2] + a[i - 3]) % 10000;//不这样处理,很快就会溢出
}
cout << a[20190324] << endl;
return 0;
}