Blue Bridge Cup C language entry-level training of the fiber-ACCI series, Blue Bridge fiber-ACCI

Source: Internet
Author: User

Blue Bridge Cup C language entry-level training of the fiber-ACCI series, Blue Bridge fiber-ACCI
Problem description

The recurrence formula of the Fibonacci series is: Fn = Fn-1 + Fn-2, where F1 = F2 = 1.

When n is large, Fn is very large. Now we want to know the remainder of Fn divided by 10007.

The input format contains an integer n. The output format outputs a row containing an integer that represents the remainder of Fn divided by 10007.

Note: In this question, the answer is to divide Fn by the remainder of 10007. Therefore, we only need to calculate this remainder without first calculating the exact Fn value, then, divide the calculated result by 10007 to obtain the remainder. It is easier to calculate the remainder directly than to calculate the original number first and then obtain the remainder.

Sample input 10 sample output 55 sample input 22 sample output 7704 data size and Convention 1 <= n <= 1,000,000.
# Include <stdlib. h> # include <stdio. h> # define MOD 10007 # define MAXN 1000001int n, I, F [MAXN]; int main () {scanf ("% d", & n ); F [1] = 1; F [2] = 1; for (I = 3; I <= n; ++ I) F [I] = (F [I-1] + F [I-2]) % MOD; printf ("% d \ n", F [n]); return 0 ;}

Related Article

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.