Advertisement
anechka_ne_plach

Untitled

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