Calculate the nth entry of a Fibonacci series. The upper limit of n is 10000.
Solution: Because the upper limit of this question is 10000, indentation is required for high precision.
# Include <iostream> # include <string. h> using namespace std; const int MAXN = 100000000; const int N = 500; const int M = 10000; struct bign {int len; int s [N]; bign () {this-> len = 1; memset (s, 0, sizeof (s);} bign (int number) {* this = number;} bign (const char * number) {* this = number;} bign change (bign cur) {bign now; now = cur; for (int I = 0; I <cur. len; I ++) now. s [I] = cur. s [cur. len-I-1]; retu Rn now;} void delZore () {// Delete the leading 0. bign now = change (* this); while (now. s [now. len-1] = 0 & now. len> 1) {now. len --;} * this = change (now);} void put () {// output value. DelZore (); printf ("% d", s [0]); for (int I = 1; I <len; I ++) printf ("% 08d ", s [I]);} bign operator = (const char * number) {memset (s, 0, sizeof (s); int dist = strlen (number ); int k = dist % 8; for (int I = 0; I <k; I ++) s [0] = s [0] * 10 + number [I]-'0'; int cnt = 0; for (int I = k; I <dist; I ++, cnt ++) s [cnt/8 + 1] = s [cnt/8 + 1] * 10 + number [I]-'0 '; len = cnt/8 + 1; return * this;} bign operator = (int number) {char string [N]; sprintf (string, "% d", number ); * this = string; return * this;} bign operator + (const bign & cur) {bign sum, a, B; sum. len = 0; a =. change (* this); B = B. change (cur); for (int I = 0, g = 0; g | I <. len | I <B. len; I ++) {int x = g; if (I <. len) x + =. s [I]; if (I <B. len) x + = B. s [I]; sum. s [sum. len ++] = x % MAXN; g = x/MAXN;} return sum. change (sum) ;}}; bign num [M + 10]; int main () {int n; num [1] = num [2] = num [3] = num [4] = 1; for (int I = 5; I <M + 5; I ++) num [I] = num [I-1] + num [I-2] + num [I-3] + num [I-4]; while (scanf ("% d", & n) = 1) {num [n]. put (); printf ("\ n");} return 0 ;}