#include using namespace std; const int squares[] = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144 }; // obviously that array should be a lot longer int binchop(const int q, const int first, const int last) { if (first > last) return -1; const int midpos = (first + last) / 2; const int midval = squares[midpos]; if (q == midval) return midpos; else if (q < midval) return binchop(q, first, midpos - 1); else return binchop(q, midpos + 1, last); } int main() { cout << "number: "; const int n = read_int(); cout << binchop(n, 0, 12) << "\n"; }