题目
数列求值
【问题描述】
给定数列 1, 1, 1, 3, 5, 9, 17, …,从第 4 项开始,每项都是前 3 项的和。求
第 20190324 项的最后 4 位数字。
【答案提交】
这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一 个 4 位整数(提示:答案的千位不为 0),在提交答案时只填写这个整数,填写 多余的内容将无法得分。
代码
1 //循环打表即可,递归就不要用了 2 #include<iostream> 3 #include<algorithm> 4 #define N 20190324 5 #define cut 10000 6 using namespace std; 7 int a[N+5]; 8 int main(){ 9 a[1]=1; 10 a[2]=1; 11 a[3]=1; 12 for(int i=4;i<=N;i++){ 13 a[i]=(a[i-1]+a[i-2]+a[i-3])%cut; 14 //cout<<a[i]<<endl; 15 } 16 cout<<a[N]<<endl;//4659 17 }
原文:https://www.cnblogs.com/memocean/p/12297174.html