// variant of Gijswijt's sequence // where we consider runs of consecutive terms with equal sums #include <stdio.h> #include <string.h> #define MAX 10000 // number of terms #define SFACTOR 100 // should be bigger the the average of the first MAX terms long long a[MAX]; // terms of the sequence bool seen[MAX * SFACTOR]; // true for partial sums int main() { memset(seen, 0, sizeof(seen)); seen[0] = true; // sum of the first 0 terms long long v = 1; long long t = 0; // partial sums for (int n=0; n<MAX; n++) { t += v; a[n] = v; printf("%lld %lld\n", n+1, a[n]); if (t < MAX * SFACTOR) { seen[t] = true; v = 1; // so far long long p = 0; // partial sum backwards for (long long k=n; k>=0; k--) { p += a[k]; if (p*v > t) { break; // no way to have a bigger value } else { // necessarily seen[t - p] == true for (long long w=2;; w++) { if (t-w*p < 0 || !seen[t-w*p]) { break; } else if (v<w) { v = w; } } } } } else { break; // must enlarge array "seen" } } return 0; }