fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int f[] = {-1,0,0,0,0,1,1,1,2,2,2,2,2,3,3,3};
  5.  
  6. int main() {
  7.  
  8. int l = 0, r = 15;
  9. while( l+1 < r ) {
  10. int x = l + (r-l)/2;
  11. if( f[x] < 2 )
  12. l = x;
  13. else
  14. r = x;
  15. }
  16.  
  17. cout << "(l;r] = " << "(" << l << ";" << r << ")" << "\n";
  18. cout << "f(r) = " << f[r] << "\n";
  19. if( f[r] == 2 )
  20. cout << "FOUND";
  21. else
  22. cout << "NOT FOUND";
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
(l;r] = (7;8)
f(r) = 2
FOUND