#include <stdio.h> #include <limits.h> int highbit(int n) { if (n) { int b=1; while (n>1) { n/=2; b*=2; } return b; } else { return 0; } } int min; void explore(int n, int b, int x, int y) { if (b==0) { int xy = x|y; if (min>xy) { min = xy; } } else { int z = (n&b) ? 1 : 0; explore(n, b/2, 2*x+z, y); explore(n, b/2, x, 2*y+z); } } int a(int n) { min = INT_MAX; explore(n, highbit(n), 0, 0); return min; } int main() { for (int n=0; n<=1<<13; n++) { printf("%d %d\n", n, a(n)); fflush(stdout); } return 0; }