#include #include #include #include using namespace std; #define MAX (1LL<<33) bitset *seen; #define CAN (1LL<<26) long long cc[CAN]; long long other(long long v, long long &index) { int w = 1; for (long long b=1;; b<<=1) { if ((v & b)==0) { if (w==CAN) { exit(1); } for (int k=0; k=MAX) { exit(2); } if (!seen->test(cc[w+k])) { index = w+k; return cc[w+k]; } } w<<=1; } } } int main() { seen = new bitset; cc[0] = 0; long long index = 1; long long v=1; for (long long n=1; n<=10000; n++) { cout << n << ' ' << index << endl; seen->set(v); v = other(v, index); } delete seen; return 0; }