蓝桥java 入门训练 Fibonacci数列-LMLPHP

蓝桥java 入门训练 Fibonacci数列-LMLPHP

import java.util.Scanner;

public class Main{
public static void main(String[] args) {
int maxn=1000000+5;
int mod=10007;
int[] Fibonacci=new int[maxn];
Fibonacci[1]=1;
Fibonacci[2]=1;
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=3;i<=n;i++)
{
Fibonacci[i]=Fibonacci[i-1]+Fibonacci[i-2];
Fibonacci[i]%=mod;
}
System.out.println(Fibonacci[n]);
sc.close();
}
}

import java.util.Scanner;
public class Main{public static void main(String[] args) {int maxn=1000000+5;int mod=10007;int[] Fibonacci=new int[maxn];Fibonacci[1]=1;Fibonacci[2]=1;Scanner sc=new Scanner(System.in);int n=sc.nextInt();for(int i=3;i<=n;i++){Fibonacci[i]=Fibonacci[i-1]+Fibonacci[i-2];Fibonacci[i]%=mod;}System.out.println(Fibonacci[n]);sc.close();}}

05-11 01:06