SDUT 2400高中数学?

    xiaoxiao2021-03-25  132

    高中数学?

    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

    4 3 4 5 6

    Example Output

    4 11 24

    41

    import java.text.DecimalFormat; import java.util.Scanner; enum color { red, orange, yellow, green, blue, violet } public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int T = sc.nextInt(); int []a = new int [110]; a[1] = 0; a[2] = 1; for(int i =3 ;i<=101;i++) { a[i] = 4*a[i-1]-5*a[i-2]; } for(int i =0; i<T;i++) { int b = sc.nextInt(); System.out.println(a[b]); } } } }

    转载请注明原文地址: https://ju.6miu.com/read-12338.html

    最新回复(0)