#include <stdio.h> #include <string.h> #define MAX 10001 int a[MAX]; bool seen[MAX]; int main() { memset(seen, 0, sizeof(seen)); int v = 0; for (int n=0; n<MAX; n++) { a[n] = v; printf("%d %d\n", n, v); bool s = seen[v]; seen[v] = true; if (!s) { v = a[a[n]]; } else { v = n-1 - a[n-1]; } } return 0; }