// kstar176.c -- solveathome job #176 (explore, Q-kstar-prereg): the three pre-registered doubling steps, walked // independently of research/attack-kstar-01.js (no shared code, no inclusion-exclusion: a direct census). // // Level-P slots: r mod P# with r mod p not in {0, p-2} for every prime p <= P. Over one period of P'# they are the // lifts s + j*P# (s a level-P slot, 0 <= j < P'#/P#). A lift is KILLED if it is 0 or -2 mod some prime q in (P, P']. // The cyclic sequence of lifts splits into maximal runs of consecutive killed lifts between surviving lifts. // hist[l] = number of maximal killed runs of length l // N_k = number of windows of k consecutive lifts all killed = sum_{l >= k} (l - k + 1) hist[l] // K* = max l with hist[l] > 0 // The survivors are the level-P' slots; their largest cyclic gap is G2(P'#), reported with its least lower position // and multiplicity as a custody check. // ./kstar176 runs the steps 13#->29#, 13#->31#, 17#->31# #include #include #include #include #include typedef uint64_t u64; typedef unsigned long long ull; static double now(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return t.tv_sec + 1e-9 * t.tv_nsec; } static int isprime(int n) { if (n < 2) return 0; for (int d = 2; d * d <= n; d++) if (n % d == 0) return 0; return 1; } #define LMAX 64 static void step(int P, int Pn) { double t0 = now(); u64 W = 1; int ps[16], np = 0; for (int p = 2; p <= P; p++) if (isprime(p)) { W *= p; ps[np++] = p; } int qs[16], nq = 0; u64 M = 1; for (int q = P + 1; q <= Pn; q++) if (isprime(q)) { qs[nq++] = q; M *= q; } // level-P tile, straight from the definition u64 *slot = malloc(sizeof(u64) * W); u64 D = 0; for (u64 r = 0; r < W; r++) { int ok = 1; for (int i = 0; i < np; i++) { u64 p = ps[i]; if (r % p == 0 || (r + 2) % p == 0) { ok = 0; break; } } if (ok) slot[D++] = r; } // start the cyclic walk at the first surviving lift in copy 0, so every run is complete u64 start = D; for (u64 i = 0; i < D && start == D; i++) { int dead = 0; for (int t = 0; t < nq; t++) { u64 q = qs[t]; if (slot[i] % q == 0 || (slot[i] + 2) % q == 0) dead = 1; } if (!dead) start = i; } if (start == D) { printf("no survivor in copy 0\n"); exit(1); } u64 hist[LMAX + 2]; memset(hist, 0, sizeof(hist)); u64 N = D * M, run = 0, survivors = 0; u64 prevSurv = slot[start], maxgap = 0, least = 0, nmax = 0, longest = 0; u64 res[16]; for (int t = 0; t < nq; t++) res[t] = slot[start] % qs[t]; u64 i = start, j = 0, pos = slot[start]; // pos = slot[i] + j*W, unreduced for (u64 n = 0; n < N; n++) { // advance to the next lift in cyclic order u64 gap; if (i + 1 < D) { gap = slot[i + 1] - slot[i]; i++; } else { gap = W - slot[i] + slot[0]; i = 0; j++; } pos += gap; for (int t = 0; t < nq; t++) { res[t] = (res[t] + gap) % qs[t]; } int dead = 0; for (int t = 0; t < nq; t++) { u64 q = qs[t]; if (res[t] == 0 || res[t] == q - 2) { dead = 1; break; } } if (dead) { run++; continue; } // survivor: close the run and the gap if (run > 0) { if (run > LMAX) { printf("run above LMAX\n"); exit(1); } hist[run]++; if (run > longest) longest = run; } run = 0; survivors++; u64 g = pos - prevSurv, lower = prevSurv % (W * M); if (g > maxgap) { maxgap = g; least = lower; nmax = 1; } else if (g == maxgap) { nmax++; if (lower < least) least = lower; } prevSurv = pos; } // the walk ends back on the start survivor after exactly N steps u64 Dn = D; for (int t = 0; t < nq; t++) Dn *= (u64)(qs[t] - 2); printf("step %d#->%d# level-%d slots per %d# = %llu, copies = %llu, lifts = %llu, survivors = %llu (D' = %llu: %s), returned to start: %s\n", P, Pn, P, P, (ull)D, (ull)M, (ull)N, (ull)survivors, (ull)Dn, survivors == Dn ? "yes" : "NO", pos == slot[start] + M * W ? "yes" : "NO"); printf(" K* = %llu\n maximal killed runs, hist[l]:", (ull)longest); for (int l = 1; l <= (int)longest; l++) printf(" %d:%llu", l, (ull)hist[l]); printf("\n N_k, k = 1..K*+1:"); for (int k = 1; k <= (int)longest + 1; k++) { u64 Nk = 0; for (int l = k; l <= (int)longest; l++) Nk += (u64)(l - k + 1) * hist[l]; printf(" %llu", (ull)Nk); } printf("\n G2(%d#) = %llu at least position %llu, attained %llu times\n", Pn, (ull)maxgap, (ull)least, (ull)nmax); fflush(stdout); fprintf(stderr, "step %d->%d %.1f s\n", P, Pn, now() - t0); free(slot); } int main(void) { step(13, 29); step(13, 31); step(17, 31); return 0; }