sdut_java_高中数学?

来源:互联网 发布:淘宝助理导出订单吗 编辑:程序博客网 时间:2024/04/27 21:47

高中数学?

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
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner in = new Scanner (System.in);while( in.hasNext() ){int t = in.nextInt();while( t-->0 ){int n = in.nextInt();F a = new F();System.out.println(a.f(n));}}in.close();}}class F{int x;F(){}public F( int n ){this.x = n;}public int f( int n ){if( n<=2 )return n-1;else return 4*f(n-1)-5*f(n-2);}}

0 0