[蓝桥杯] Fibonacci数列 入门

原题链接


import java.util.Scanner;//导入Scanner类

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[1000010];
        int n = sc.nextInt();
        arr[0]=arr[1]=1;
        for (int i = 2; i < n; i++) {
            arr[i]=(arr[i-1]+arr[i-2])%10007;
        }
        sc.close();
        System.out.print(arr[n-1]);
    }
}

posted @ 2018-11-12 20:00  Ruohua3kou  阅读(163)  评论(0编辑  收藏  举报