给定数列1, 1, 1, 3, 5, 9, 17, …,从第4 项开始,每项都是前3 项的和。求
第20190324 项的最后4 位数字。
不愧是暴力杯
#include<iostream>
using namespace std;
const int N = 20190324;
long long a[N] = { 1,1,1 };
int main()
{
int p = 10000;
for (int i = 3; i < N; i++)
{
a[i] = a[i - 3] % p + a[i - 2] % p + a[i - 1] % p;
a[i] %= p;
}
cout << a[N - 1] << endl;
return 0;
}