Exercise Starter Set @ Blue Bridge Cup javaB group (4) Fourth Question: Fibonacci series

Exercise Starter Set @ Blue Bridge Cup javaB group (4) Fourth Question: Fibonacci series

Keywords: the number of columns, modulo

Problem Description

Fibonacci recursion formulas for the number of columns: Fn = Fn-1 + Fn-2, where F1 = F2 = 1.

When n is relatively large, Fn is very great, and now we want to know, Fn is divided by the number 10007 is.

Input format
input contains an integer n.
Output format
output one line containing an integer representing the Fn remainder of the division of 10007.
Description: In this problem, the answer is to require Fn is divided by 10007, so we can figure this out as long as the remainder can be, without the need to calculate the exact value of Fn, then the result is calculated by dividing the number 10007 to take over direct calculation the remainder often than first calculate the original number and then take the remainder simple.

Input Sample
10
Sample output
55
Sample Input
22
sample output
7704
data size and Conventions
1 <= n <= 1,000,000.

Code:

public class Main{
public static void main( String[] args ){
java.util.Scanner s=new java.util.Scanner(System.in);
int n=s.nextInt();
if(n>=1&&n<=1000000){
long[] fibonacci=new long[1000000];
fibonacci[0]=0;
fibonacci[1]=1;
for(int i=2;i<1000000;i++){
fibonacci[i]=fibonacci[i-2]+fibonacci[i-1];
}
System.out.println(fibonacci[n]%10007);
}
else System.out.println(“数据规模与约定:1 <= n <= 1,000,000”);
}
}

Published 29 original articles · won praise 1 · views 1106

Guess you like

Origin blog.csdn.net/DAurora/article/details/104126213