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