#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using I = __int128; vector divisors(__int128 x) { char cmd[50] = "factor "; VI digits; for (auto t = x; t; t /= 10) digits.emplace_back(t % 10); if (digits.empty()) digits.emplace_back(0); int ptr = 7; for (int x : digits | views::reverse) cmd[ptr++] = '0' + x; cmd[ptr++] = '\0'; std::array buffer; std::string result; FILE* pipe = popen(cmd, "r"); assert(pipe); while (fgets(buffer.data(), static_cast(buffer.size()), pipe) != nullptr) { result += buffer.data(); } pclose(pipe); ptr = 0; while (result[ptr] != ':') ptr++; ptr++; istringstream ss(result.substr(ptr)); vector factors; for (string n_str; ss >> n_str;) { I n = 0; for (char c : n_str) n = 10 * n + (c - '0'); factors.emplace_back(n); } vector res{1}; int csz = 1; I last = 0; for (I f : factors) { if (f != last) csz = res.size(), last = f; int ptr = ssize(res) - csz; rep(_, csz) res.emplace_back(res[ptr++] * f); } sort(all(res)); return res; } string I2str(I x) { string res; while (x) res += '0' + x % 10, x /= 10; reverse(all(res)); if (res.empty()) res = "0"; return res; } constexpr long long INF = 1002003004005006007; constexpr I IINF = I(INF) * INF / 8; } int main() { ios::sync_with_stdio(false); cin.tie(0); string n_str; cin >> n_str; I n = 0; for (char c : n_str) n = 10 * n + (c - '0'); // auto divs = divisors(n); // for (auto d : divs) { // cout << I2str(d) << endl; // } vector> ans; for (int e = 1;; e++) { // cout << e << endl; if (e == 1) { // (r-l+1)(l+r)/2 I n2 = 2 * n; I t2 = n2 & -n2; int t = 0; while (!(t2 >> t & 1)) t++; I m = n2 >> t; auto divs = divisors(m); rep(i, ssize(divs)) { I D1 = divs[i], D2 = divs.end()[-1-i]; for (auto [d1, d2] : {pair(D1 << t, D2), pair(D1, D2 << t)}) { if (d1 > d2) continue; I l = (d2 - d1) >> 1; I r = (d1 + d2 - 1) >> 1; ans.emplace_back(1, l, r); } } sort(all(ans)); } else if (e == 2) { I n6 = n * 6; auto divs = divisors(n6); for (I d1 : divs) { I d2 = n6 / d1; if ((d1 % 2 == 0) == (d2 % 2 == 0)) continue; if ((d1 % 3 == 0) == (d2 % 3 == 0)) continue; // constexpr auto mul = [](I x, I y) { // if (__builtin_mul_overflow(x, y, &x)) x = INF; // return x; // }; auto f = [&](I l) { I r = l + d1 - 1; I tmp; I res = 0; if (__builtin_mul_overflow(l,l,&tmp)) return IINF; if (__builtin_mul_overflow(2,tmp,&tmp)) return IINF; if (__builtin_add_overflow(tmp,res,&res)) return IINF; if (__builtin_mul_overflow(l,r,&tmp)) return IINF; if (__builtin_mul_overflow(2,tmp,&tmp)) return IINF; if (__builtin_add_overflow(tmp,res,&res)) return IINF; res -= l; if (__builtin_mul_overflow(r,r,&tmp)) return IINF; if (__builtin_mul_overflow(2,tmp,&tmp)) return IINF; if (__builtin_add_overflow(tmp,res,&res)) return IINF; if (__builtin_add_overflow(r,res,&res)) return IINF; return res; }; I l = 0, r = 1; while (f(r) < d2) l = r, r *= 2; while (r - l > 1) { I c = (l + r) >> 1; (f(c) < d2 ? l : r) = c; } if (f(r) == d2) ans.emplace_back(e, r, r + d1 - 1); } } else { if (I(1) << e > n) break; int l = 1; I now = 0; for (int r = 1;; r++) { I re = 1; rep(_, e) if (__builtin_mul_overflow(re, r, &re)) { re = n + 1; break; } if (re > n) break; now += re; while (now > n) { I le = 1; rep(_, e) le *= l; now -= le; l++; } if (now == n) ans.emplace_back(e, l, r); } } } cout << ans.size() << '\n'; for (auto [e, l, r] : ans) cout << e << ' ' << I2str(l) << ' ' << I2str(r) << '\n'; }