Find the last four digits of the Fibonacci series in xidian 1232

Source: Internet
Author: User

Description defines a sequence: f [0] = 0, f [1] = 1, f [n] = f [n-1] + f [N-2]. So what is f [10] and f [100]? What is f [1000... the final result of the simulation is obviously very large. Now, as long as you output the last four digits of f [n], the previous 0 will not be output. If the answer is 10000, the output is 0. If the answer is 10001, output 1.0 ≤ n ≤ 1,000,000,000 Input Multiple groups of data, the last four pieces of Sample Input4Sample Output3HintSourceLLL in each group of nOutputf [n] See mod = 10000 and there are 1000000000 pieces of data, so there must be duplicates. If f (n) = f (1) & f (n-1) = f (0). At this time, the loop section finds the result as 15000, as if [cpp] # include <iostream> # include <cstdio> using namespace std; int a [30001]; int main () {int n; a [0] = 0; a [1] = 1; (Int I = 2; I <= 30000; I ++) a [I] = (a [I-1] % 10000 + a [I-2] % 10000) % 10000; while (scanf ("% d", & n )! = EOF) {if (n <= 30000) printf ("% d \ n", a [n]); else printf ("% d \ n ", a [n % 30000]);} return 0 ;}

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.