The first four digits of this question refer to others' ideas. I found that the first few digits are usually called logarithm!
Not to mention the last four digits. When n> = 40, the number of digits is greater than 8. In addition, the cycle of the last four digits is 15000. In this way, the table is used to find the last four digits.
Use the first four digitsThe generic formula of the Fibonacci series. After reading Baidu encyclopedia, I learned this formula =. What's interesting is that when n is infinite, the ratio of the previous one to the next one is approaching.Gold separated by 0.618... Orz. In other words, an can be expressed as T * 10 ^ K (T is a floating point number> 1), and the logarithm log10 (an) =
Log10 (t) + K, where 0 <log10 (t) <1, so after obtaining the logarithm minus the integer part is log10 (t), then pow (10, log10 (t )) restore T. Note: Here is a trick, that is, when n> = 40, the last half of the square brackets tend to be infinitely small and can be ignored.
UpperCode:
# Include <map> # include <set> # include <list> # include <queue> # include <deque> # include <stack> # include <string> # include <time. h> # include <cstdio> # include <math. h> # include <iomanip> # include <cstdlib> # include <limits. h> # include <string. h> # include <iostream> # include <fstream> # include <algorithm> using namespace STD; # define ll long # define min int_min # define Max int_max # define PI ACOs (-1.0) # define N 2 # Define fre freopen ("input.txt", "r", stdin) # define FF freopen ("output.txt", "W", stdout ); # define mod analyze int fib [45] = {20000, 3}; int last [] = {, 3 }; double Gao = (1 + SQRT (5.0)/2.0; int main () {int I, j; for (I = 5; I <15000; I ++) {last [I] = (last [I-1] + last [I-2]) % mod ;}for (I = 5; I <40; I ++) FIB [I] = fib [I-1] + fib [I-2]; int N; while (scanf ("% d", & N )! = EOF) {int I, j; If (n <40) {printf ("% d \ n", FIB [N]);} else {double ans = N * log10 (GAO)-log10 (5.0)/2.0; ANS-= (INT) ans; ans = POW (10, ANS ); while (ANS <1000) {ans * = 1000;} printf ("% d... % 4.4d \ n ", (INT) ans, last [n % 15000]) ;}} return 0 ;}