The task itself: http://www.codeabbey.com/index/task_view/fibonacci-sequence--ru , my code:
#include <iostream> #include <vector> using namespace std; int main() { vector<long double> fib{0, 1}; for(int i = 1; i < 1000; i++) // По условию все числа из первой тысячи // значений последовательности { fib.push_back(fib[i] + fib[i-1]); } int N; // Первая строчка должна содержать количество проводимых тестов cin >> N; long double value[N]; for(int i = 0; i < N; i++) { cin >> value[i]; } int begin, end; for (int i = 0; i < N; i++) { if(value[i] > fib[fib.size() / 2]) // Если value находится во второй половине последовательности { begin = fib.size() / 2; while(value[i] > fib[begin]) { begin /= 2; } begin *= 2; // Возвращаюсь на шаг назад // ибо после выполнения цикла // value выходит из диапозона end = fib.size(); for( ; begin < end; begin++) { if(fib[begin] == value[i]) {cout << begin << " "; break;} } } else { end = fib.size() / 2; while (value[i] < fib[end]) { end /= 2; } end *= 2; // То же самое что и в первой ветви begin = 0; for ( ; begin < end; begin++) { if(fib[begin] == value[i]) {cout << begin << " "; break;} } } } return 0; } One could not make such a game and just write
for(int i = 0; i < N; i++) for(int j = 0; j < fib.size(); j++) if(value[i] == fib[j]) cout << j + 1 << " "; But while reading one smart book, it became interesting for me to recreate a simplified version of the binary_search () algorithm and in general, that's it :)
On the site with the task also kindly offer data entry to check the program, I was given this: 
For the sake of a small test, I tried to enter only a few of them, and more specifically, the very first, second, and fourth. To my surprise, all I got on the way out was nothing.
Disappointed in my code, I redid the code before
vector <long double> fib {0, 1};
long double value;
cin >> value;
int i = 1;
int number_of_element = 1;
while (value> fib.back ()) {
fib.push_back (fib [i] + fib [i-1]);
i ++;
number_of_element ++;
}
cout << fixed << "Element:" << fib [i-1] << "It's number:" << --number_of_element;
to find out what I'm wrong about and at the same time check, mb just numbers come across more than the first thousand. I entered the same thing in turn: the first, second and third numbers from Test data. In all three results, the number obtained by the prog was almost identical to that entered, up to about 19 characters (I miscalculated many times on this, this is not accurate), the element number also did not exceed a thousand. Based on this, I concluded that the car just had an error after a certain number of characters. Is there any way to fix this problem?



