中数学?
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
高中数学大家都学过数列,其中一个重要的概念就是数列的通项,可以代表数列中每一项的一个表达式。
今天我们的问题就跟通项有关系,说,给你一个数列的通项和数列中的前几项,希望你能求出它的第n项。
通项表达式如下:
F(1) = 0;
F(2) = 1;
F(n) = 4*F(n-1)-5*F(n-2);
今天我们的问题就跟通项有关系,说,给你一个数列的通项和数列中的前几项,希望你能求出它的第n项。
通项表达式如下:
F(1) = 0;
F(2) = 1;
F(n) = 4*F(n-1)-5*F(n-2);
Input
输入数据第一行是一个正整数T,T<100。接下来T行,每行一个整数n, 2<n<50。
Output
输出有T行,对于输入中每行中的n按照通项计算出F(n)。
Example Input
4
3
4
5
6
Example Output
4
11
24
41
#include <iostream>
#include<math.h>
#include<cstdio>
using namespace std;
int c[100000];
void answer(int a)
{
c[1]=0;
c[2]=1;
for(int i=3;i<=a;i++)
c[i]=4*c[i-1]-5*c[i-2];
cout<<c[a]<<endl;
}
int main()
{
int n;
cin>>n;
int t;
while(n--)
{
cin>>t;
answer(t);
}
return 0;
}