Advertisement
anechka_ne_plach

Untitled

Nov 6th, 2021
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 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 M = (L + R) / 2;
  14.     static const int value = BinarySearch<
  15.     If<(M * M >= N), M, R>::value,
  16.     If<(M * M >= N), L, M>::value,
  17.     R - L,
  18.     N>::value;
  19. };
  20.  
  21. template<int L, int R, int N>
  22. struct BinarySearch<L, R, 1, N> {
  23.     static const int value = R;
  24. };
  25.  
  26. template<int L, int R, int N>
  27. struct BinarySearch<L, R, 0, N> {
  28.     static const int value = R;
  29. };
  30.  
  31. template<int N>
  32. struct Sqrt {
  33.     static const int value = BinarySearch<0, N, N, N>::value;
  34. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement