#include<iostream>#include<vector>usingnamespace std;using Rank =int;classFib{private:Rank g ,f;public:Fib(Rank n){f =0; g=1;//f 代表 fib(k -1) g 代表 fib(k)while(0< n--){g = g + f;f = g - f;}}Rank get(){return g;}Rank next(){g = g + f;f = g -f;return g;};Rank pre(){f = g-f;g = g-f;return g;}};template<typenameT>static Rank fibSearch(T *A,const T &e,Rank lo,Rank hi){for(Fib fib(hi - lo); lo < hi;){while( hi -lo < fib.get()) fib.pre();Rank mi = lo + fib.get()-1;(e < A[mi])? hi = mi : lo = mi +1;}return lo -1;}intmain(){std::vector<Rank> test{1,3,6,8,9,11,13,17,20};Rank index = fibSearch<Rank>(test.data(),14,0,test.size());cout <<"index: "<< index <<endl;return0;}