/// P3(x, a) counts the numbers <= x that have exactly 3 /// prime factors each exceeding the a-th prime. /// Space complexity: O(pi(sqrt(x))). /// int64_t P3(int64_t x, int64_t a, int threads) { print(""); print("=== P3(x, a) ==="); print("Computation of the 3rd partial sieve function"); double time = get_wtime(); vector<int32_t> primes = generate_primes(isqrt(x)); int64_t y = iroot<3>(x); int64_t pi_y = pi_bsearch(primes, y); int64_t sum = 0; threads = ideal_num_threads(threads, pi_y, 100); #pragma omp parallel for num_threads(threads) schedule(dynamic) reduction(+: sum) for (int64_t i = a + 1; i <= pi_y; i++) { int64_t xi = x / primes[i]; int64_t bi = pi_bsearch(primes, isqrt(xi)); for (int64_t j = i; j <= bi; j++) sum += pi_bsearch(primes, xi / primes[j]) - (j - 1); } print("P3", sum, time); return sum; }
/// Calculate the number of primes below x using the /// Deleglise-Rivat algorithm. /// Run time: O(x^(2/3) / (log x)^2) operations, O(x^(1/3) * (log x)^3) space. /// int64_t pi_deleglise_rivat_parallel1(int64_t x, int threads) { if (x < 2) return 0; double alpha = get_alpha(x, 0.0017154, -0.0508992, 0.483613, 0.0672202); int64_t x13 = iroot<3>(x); int64_t y = (int64_t) (x13 * alpha); int64_t z = x / y; int64_t p2 = P2(x, y, threads); vector<int32_t> mu = generate_moebius(y); vector<int32_t> lpf = generate_least_prime_factors(y); vector<int32_t> primes = generate_primes(y); int64_t pi_y = pi_bsearch(primes, y); int64_t c = PhiTiny::get_c(y); int64_t s1 = S1(x, y, c, threads); int64_t s2 = S2(x, y, z, c, primes, lpf, mu, threads); int64_t phi = s1 + s2; int64_t sum = phi + pi_y - 1 - p2; return sum; }