蓝桥杯 基础练习 Fibonacci数列

问题描述

在这里插入图片描述

Java 代码实现

import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        int a = 1;
        int b = 1;
        int sum = 1;
        
        if (n < 3) {
            System.out.println(1);
        } else {
            for (int i = 3; i <= n; ++i) {
                sum = (a+b)%10007;
                a = b;
                b = sum;
            }
            System.out.println(b);
        }
        
        in.close();
    }
}
posted @ 2022-01-20 01:19  Acx7  阅读(42)  评论(0编辑  收藏  举报