#include #include #define MAX 10000 int a[MAX+1]; int fmap[MAX+1]; int main() { memset(fmap, 0, sizeof(fmap)); int *forbidden = &fmap[MAX/2]; for (int n=1; n<=MAX; n++) { int jmax = (n-1)/2; int fmax = 0; for (int j=1; j<=jmax; j++) { int f = 2*a[n-j]-a[n-2*j]; if (forbidden[f]!=n) { forbidden[ f ] = n; if (fmax < f || j==1) { fmax = f; } } } for (int v=1;; v++) { if (forbidden[+v]!=n) { a[n] = +v; break; } } if (n>2) { printf("%d %d\n", n, fmax); fflush(stdout); } } return 0; }