Blue Bridge Cup-introductory training-fibonacci series

Source: Internet
Author: User

Introductory training Fibonacci Sequence time limit: 1.0s memory limit: 256.0MBProblem description

fibonacci sequence is: Fn =fn-1 +fn-2 , wherein F1 =f2 = 1.

When n is large, fn is also very large, and now we want to know what the remainder of fn divided by 10007 is.

Input format input contains an integer n. The output format outputs a line that contains an integer representing the FNDivide by the remainder of 10007.

Note: In the subject, the answer is to ask Fn divided by 10007 of the remainder, so as long as we can calculate the remainder, without first calculating the exact value of fn , and then dividing the calculated result by 10007 to take the remainder, The direct calculation of the remainder is often simpler than calculating the original number and then taking more than the first.

Sample input 10 Sample Output 55 Sample input 22 sample output 7704 data scale and Convention 1 <= N <= 1,000,000.
#include <iostream>using namespace Std;int f[1000001];int main () {    int n;    F[1]=1;f[2]=1;    cin>>n;    for (int i=3;i<=1000000;i++)    {        f[i]=f[i-1]+f[i-2];        f[i]%=10007;    }    cout<<f[n];    return 0;}









Blue Bridge Cup-introductory training-fibonacci series

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.