81

蓝桥杯准备-小四的窝-51CTO博客

 6 years ago
source link: http://blog.51cto.com/13416247/2067072
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

蓝桥杯准备

package lanQiao;

import java.util.Scanner;

/**
 * @author 国真
 *   Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1,
 *  当n比较大时,Fn也非常大,现在我们想知道,Fn除以10007的余数是多少
 */
public class demo1 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();  //a为输入的数

        int[] arr = new int[a+1];   //new了int类型的数组,数组长度为a+1,原因是数组长度从0开始
        arr[1] = arr[2] = 1;
        for(int i=3; i<arr.length; i++){
            arr[i] = (arr[i-1]+arr[i-2]) % 10007;   //arr这个数组中只存放着%1000后的余数,(a + b) % p = (a % p + b % p) % p
        }
        System.out.println(arr[a]);
    }

}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK