Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- 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<int64_t L, int64_t R, int64_t, int N>
- struct BinarySearch {
- static const int64_t value = BinarySearch<
- If<(((L + R) / 2) * ((L + R) / 2) >= N), L, ((L + R) / 2)>::value,
- If<(((L + R) / 2) * ((L + R) / 2) >= N), ((L + R) / 2), R>::value,
- R - L,
- N>::value;
- };
- template<int64_t L, int64_t R, int N>
- struct BinarySearch<L, R, 1, N> {
- static const int value = R;
- };
- template<int64_t L, int64_t 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