1410221224-hd-hat's Fibonacci

Source: Internet
Author: User
Hat's Fibonacci

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 7857 accepted submission (s): 2553


Problem descriptiona Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1.
F (1) = 1, F (2) = 1, F (3) = 1, F (4) = 1, F (n> 4) = f (n-1) + f (n-2) + f (n-3) + f (n-4)
Your task is to take a number as input, and print that maid number.

Inputeach line will contain an integers. process to end of file.

Outputfor each case, output the result in a line.
Sample Input
100

Sample output
4203968145672990846840663646Note:No generated Fibonacci number in excess of 2005 digits will be in the test data, ie. F(20) = 66526 has 5 digits.
This is an extension of the Fibonacci number. On the one hand, we use the Fibonacci series, and on the other hand, we need to add and subtract large numbers. The error message returned when the array size exceeds the memory size. You can change the array format to char type, which can reduce the memory size by 1/4. Code
# Include <stdio. h> # include <string. h> char num [10000] [2010]; // If the int type is used, the memory is exceeded. Therefore, the char type int Len [10000] is used. // records the length of each int main () {int N; int I, j, k; int A, B; for (I = 1; I <10000; I ++) for (j = 0; j <2010; j ++) num [I] [J] = '0'; // initialize num [1] [0] = '1 '; num [2] [0] = '1'; num [3] [0] = '1'; num [4] [0] = '1 '; len [1] = Len [2] = Len [3] = Len [4] = 1; a = 0; for (I = 5; I <10000; I ++) {B = 0; For (j = 0; j <= Len [I-1]; j ++) {B = a + num [I-1] [J]-'0' + num [I-2] [J]-'0' + num [I-3] [J]-'0' + num [I-4] [J]-'0'; num [I] [J] = B % 10 + '0'; A = B/10 ;} // addition and subtraction of large numbers if (Num [I] [Len [I-1]! = '0') Len [I] = Len [I-1] + 1; else Len [I] = Len [I-1]; If (LEN [I]> 2005) break ;} while (scanf ("% d", & N )! = EOF) {for (I = Len [N]-1; I> = 0; I --) printf ("% C", num [N] [I]); printf ("\ n");} return 0 ;}

1410221224-hd-hat's Fibonacci

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.