高中数学?

来源:互联网 发布:2017eia原油库存数据 编辑:程序博客网 时间:2024/05/16 18:33

中数学?

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

Problem Description

高中数学大家都学过数列,其中一个重要的概念就是数列的通项,可以代表数列中每一项的一个表达式。
 今天我们的问题就跟通项有关系,说,给你一个数列的通项和数列中的前几项,希望你能求出它的第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

43456

Example Output

4112441
#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;}

0 0
原创粉丝点击