fork download
  1. #include <iostream>
  2. #include <cstdint>
  3.  
  4. using namespace std;
  5.  
  6. const int32_t N = 10;
  7. static_assert(N > 3, "N should be greater than 3");
  8.  
  9. const int32_t c_limit = 3 * (1 << (N-2)) - 1;
  10.  
  11. template<size_t s>
  12. int32_t shr(int32_t n) { return n >> s; }
  13.  
  14. bool cond_1(const int32_t u, const int32_t v) { return (-1 + shr<8>(u)) == (-shr<3>(v) + shr<2>(v)); }
  15. bool cond_2(const int32_t u, const int32_t v) { return ( shr<8>(u) - shr<7>(u)) == ( shr<4>(v) - shr<3>(v)); }
  16. bool cond_3(const int32_t u, const int32_t v) { return (-shr<7>(u) + shr<6>(u)) == (-shr<5>(v) + shr<4>(v)); }
  17. bool cond_4(const int32_t u, const int32_t v) { return ( shr<6>(u) - shr<5>(u)) == ( 1 - shr<8>(v)); }
  18. bool cond_5(const int32_t u, const int32_t v) { return (-shr<5>(u) + shr<4>(u)) == ( 1 - shr<0>(v)); }
  19. bool cond_6(const int32_t u, const int32_t v) { return ( shr<4>(u) - shr<3>(u)) == ( shr<8>(v) + shr<7>(v)); }
  20. bool cond_7(const int32_t u, const int32_t v) { return (-shr<3>(u) + shr<2>(u)) == (-shr<7>(v) + shr<6>(v)); }
  21. bool cond_8(const int32_t u, const int32_t v) { return ( shr<2>(u) - shr<1>(u)) == (-shr<1>(v) + shr<0>(v)); }
  22. bool cond_9(const int32_t u, const int32_t v) { return (-shr<1>(u) + shr<0>(u)) == ( shr<2>(v) - shr<1>(v)); }
  23. bool cond_10(const int32_t u, const int32_t v) { return (-shr<0>(u) + 1) == ( shr<6>(v) - shr<5>(v)); }
  24.  
  25. int main()
  26. {
  27. size_t count = 0;
  28. for (int32_t u = 767; u <= c_limit; ++u)
  29. {
  30. for (int32_t v = 767; v <= c_limit; ++v)
  31. {
  32. if (cond_1(u, v) && cond_2(u, v) && cond_3(u, v) && cond_4(u, v) && cond_5(u, v) &&
  33. cond_6(u, v) && cond_7(u, v) && cond_8(u, v) && cond_9(u, v) && cond_10(u, v))
  34. {
  35. cout << "(" << u << ", " << v << ")" << endl;
  36. count++;
  37. }
  38. }
  39. }
  40.  
  41. cout << count << " pairs" << endl;
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
0 pairs