Blue Bridge Fibonacci number sequences recurrence formula JAVA

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,
the Fn is divided by the number 10007 is.
Input
plurality of sets of test data
input contains an integer n. 1 <= n <= 1,000,000.
Output
each line of output contains an integer, Fn represents the remainder of the division 10007.
The Input the Sample
10
22 is
the Sample the Output
55
7704

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int F1 = 1;
		int F2 = 1;
		int temp = 0;
		for (int i = 3; i <= n; i++) {     //前两位强给1,下面满足题目规律
			temp = F1+F2;
			F1 = F2;
			F2 = temp;
		}
		System.out.println(temp % 10007);
	}

Small Theater: between now and forever, there are numerous possible.

Published 108 original articles · won praise 113 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43771695/article/details/104654917