#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 25000 bool seen[MAX]; long long unseen = 1; long long mask = 1; // (mask & unseen) = unseen long long sum = 0; // sum of previous terms long long other() { if (sum==0) { return 2; } else { while ((mask & unseen)!=unseen) { mask = 2*mask+1; } for (long long m = mask;; m = 2*m+1) { long long rem = sum; long long best = MAX; while (rem) { long long can = rem & m; if (can < MAX && !seen[can] && can < best) { best = can; } rem /= 2; } if (best < MAX) { return best; } if ((sum & m)==sum) { fprintf(stderr, "# the end\n"); fflush(stdout); exit(1); } } } } int main() { memset(seen, 0, sizeof(seen)); seen[0] = true; for (int n=1; n<=10000; n++) { long long v = other(); seen[v] = true; sum += v; printf("%d %lld\n", n, v); fflush(stdout); } return 0; }