Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<bool, int T, int F> struct If;
- template<int T, int F>
- struct If<true, T, F> {
- static const int value = T;
- };
- template<int T, int F>
- struct If<false, T, F> {
- static const int value = F;
- };
- template<int L, int R, int, int N>
- struct BinarySearch {
- static const int M = (L + R) / 2;
- static const int value = BinarySearch<
- If<(M * M >= N), M, R>::value,
- If<(M * M >= N), L, M>::value,
- R - L,
- N>::value;
- };
- template<int L, int R, int N>
- struct BinarySearch<L, R, 1, N> {
- static const int value = R;
- };
- template<int L, int R, int N>
- struct BinarySearch<L, R, 0, N> {
- static const int value = R;
- };
- template<int N>
- struct Sqrt {
- static const int value = BinarySearch<0, N, N, N>::value;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement