[ create a new paste ] login | about

Link: http://codepad.org/Pm8U6R89    [ raw code | output | fork ]

C++, pasted on Nov 29:
#include <iostream>
#include <vector>
using namespace std;

#define MID(a, b) ((a+b)/2)
#define POW(a) (a*a)

template<int res, int l = 1, int r = res>
class SQRT;

template<int res, int r>
class SQRT<res, r, r> {
  public:
    static const int value = r;
};

template <int res, int l, int r>
class SQRT {
  public:
    static const int value = SQRT<res, (POW(MID(r, l)) >= res ? l : MID(r, l)+1), (POW(MID(r, l)) >= res ? MID(r, l) : r)>::value;
};

int main() {
  vector<int> huj(20);
  huj[16] = 16;
  cout << huj[SQRT<256>::value] << endl;
  return 0;
}


Output:
1
16


Create a new paste based on this one


Comments: