#include #include using namespace std; static int const fibonacci_numbers[47] = { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2147483647 }; static int find_fibonacci_number( int n ) { for ( int i = 1; true; ++i ) { if ( fibonacci_numbers[i] >= n ) { return fibonacci_numbers[i - 1]; } } } template static int search( Type obj, Type *array, int a, int c, int count, double d ) { if ( c < a ) { return -10000; } else if ( a == c ) { if ( array[a] == array[c] ) { return count + 1; } else { return -10000; } } int b; if ( obj - array[a] > array[c] - obj ) { b = static_cast( c - (c - a)*d + 0.5 ); } else { b = static_cast( a + (c - a)*d + 0.5 ); } if ( array[b] == obj ) { return count + 1; } else if ( obj < array[b] ) { return search( obj, array, a, b - 1, count + 1, d ); } else { return search( obj, array, b + 1, c, count + 1, d ); } } int search( int obj, int *array, int n, double d ) { return search( obj, array, 0, n - 1, 0, d ); } int main() { int array[10000000]; for ( int i = 0; i < 10000000; ++i ) { array[i] = i; } double d2; for ( double d = 0.5; d >= 0.09999; d -= 0.001 ) { for ( int i = 9999999; i < 10000000; i += 1 ) { int sum = 0; for ( int j = 0; j < i; ++j ) { int s = search( j, array, i, d ); sum += s; } if ( d == 0.5 ) { d2 = static_cast( sum )/i; } cout << "[" << d << "," << (static_cast( sum )/i)/d2 << "]," << endl; } } return 0; }