boolcheck(int x, int y){ if (std::__gcd(x, y) != 1) return0; int c = 0; for (c = 1; x != 1 || y != 1; ++c) { x = abs(x - y), std::swap(x, y); if (c > 50) return0; } return x <= 1 && c <= 50; }
voidconstruct(int x, int y){ int c = 0, _x = x, _y = y; for (c = 1; x != 1 || y != 1; ++c) x = abs(x - y), std::swap(x, y); sz = c, x = _x, y = _y; memset(a, 0, sizeof(a)); for (; x != 1 || y != 1; --c) { a[c][c] = a[c][c - 1] = 1; if (x >= y) a[c - 1][c] = -1; else a[c - 1][c] = 1; x = abs(x - y), std::swap(x, y); } assert(c == 1); a[1][1] = x; }
voiddickdreamer(){ std::cin >> n; if (n == 1) returnvoid(std::cout << "1\n1\n"); int p = n * (sqrtl(5) - 1) / 2, m = -1; for (int i = 0;; ++i) { if (p - i >= 0 && check(n, p - i)) { m = p - i; break; } if (check(n, p + i)) { m = p + i; break; } } construct(n, m); std::cout << sz << '\n'; for (int i = 1; i <= sz; ++i) for (int j = 1; j <= sz; ++j) std::cout << a[i][j] << " \n"[j == sz]; // std::cerr << n << ' ' << << '\n'; }