Advertisement
anechka_ne_plach

sort

Nov 12th, 2021
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <stdint.h>
  2.  
  3. template<bool, int T, int F> struct If;
  4. template<int T, int F>
  5. struct If<true, T, F> {
  6.     static const int value = T;
  7. };
  8.  
  9. template<int T, int F>
  10. struct If<false, T, F> {
  11.     static const int value = F;
  12. };
  13.  
  14. template<int64_t L, int64_t R, int64_t, int N>
  15. struct BinarySearch {
  16.     static const int64_t value = BinarySearch<
  17.         If<(((L + R) / 2) * ((L + R) / 2) >= N), L, ((L + R) / 2)>::value,
  18.         If<(((L + R) / 2) * ((L + R) / 2) >= N), ((L + R) / 2), R>::value,
  19.         R - L,
  20.         N>::value;
  21. };
  22.  
  23. template<int64_t L, int64_t R, int N>
  24. struct BinarySearch<L, R, 1, N> {
  25.     static const int value = R;
  26. };
  27.  
  28. template<int64_t L, int64_t R, int N>
  29. struct BinarySearch<L, R, 0, N> {
  30.     static const int value = R;
  31. };
  32.  
  33. template<int N>
  34. struct Sqrt {
  35.     static const int value = BinarySearch<0, N, N, N>::value;
  36. };
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement