<commit_before>///
/// @file  Pk.cpp
/// @brief Partial sieve functions.
///
/// Copyright (C) 2014 <NAME>, <<EMAIL>>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#include "pi_bsearch.hpp"
#include "pmath.hpp"

#include <primecount.hpp>
#include <primesieve.hpp>
#include <algorithm>
#include <stdint.h>
#include <vector>

#ifdef _OPENMP
  #include <omp.h>
  #include "get_omp_threads.hpp"
#endif

using namespace std;

namespace primecount {

/// 2nd partial sieve function.
/// P2(x, a) counts the numbers <= x that have exactly 2 prime
/// factors each exceeding the a-th prime.
/// Space complexity: O(sqrt(x / y)).
///
int64_t P2(int64_t x, int64_t a, int64_t y /* pi(a) */)
{
  int64_t limit = x / y;
  int64_t sqrt_limit = isqrt(limit);
  int64_t sum = 0; // \sum_{i=a+1}^{b} pi(x / primes[i]) - (i - 1)
  int64_t pix = 1; // start counting primes at 3
  int64_t sqrtx = isqrt(x);
  int64_t b = pi_legendre(sqrtx, 1);
  int64_t segment_size = next_power_of_2(sqrt_limit);

  if (b <= a)
    return sum;

  vector<int32_t> primes;
  primes.push_back(0);
  primesieve::generate_primes(sqrt_limit, &primes);
  primesieve::iterator iter(sqrtx + 1);
  int64_t stop = x / iter.previous_prime();
  vector<char> sieve(segment_size);
  vector<int64_t> next(primes.size());

  for (size_t i = 1; i < primes.size(); i++)
    next[i] = (isquare(primes[i]) - /* low */ 3) % segment_size;

  // segmented sieve of Eratosthenes
  for (int64_t low = 3; low <= limit; low += segment_size)
  {
    fill(sieve.begin(), sieve.end(), 1);<commit_msg>Signature of P2(x, a) modified<commit_after>///
/// @file  Pk.cpp
/// @brief Partial sieve functions.
///
/// Copyright (C) 2014 <NAME>, <<EMAIL>>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#include "pi_bsearch.hpp"
#include "pmath.hpp"

#include <primecount.hpp>
#include <primesieve.hpp>
#include <algorithm>
#include <stdint.h>
#include <vector>

#ifdef _OPENMP
  #include <omp.h>
  #include "get_omp_threads.hpp"
#endif

using namespace std;

namespace primecount {

/// 2nd partial sieve function.
/// P2(x, a) counts the numbers <= x that have exactly 2 prime
/// factors each exceeding the a-th prime.
/// Space complexity: O((x / primes[a])^(1/2)).
///
int64_t P2(int64_t x, int64_t a)
{
  vector<int32_t> primes;
  primes.push_back(0);
  primesieve::generate_n_primes(a, &primes);
  int64_t limit = (a > 0) ? x / primes[a] : x;
  int64_t sqrt_limit = isqrt(limit);
  int64_t sum = 0; // \sum_{i=a+1}^{b} pi(x / primes[i]) - (i - 1)
  int64_t pix = 1; // start counting primes at 3
  int64_t sqrtx = isqrt(x);
  int64_t b = pi_legendre(sqrtx, 1);
  int64_t segment_size = next_power_of_2(sqrt_limit);

  if (b <= a)
    return sum;

  primesieve::iterator iter(sqrtx + 1);
  int64_t stop = x / iter.previous_prime();
  vector<char> sieve(segment_size);
  vector<int64_t> next(primes.size());

  for (size_t i = 1; i < primes.size(); i++)
    next[i] = (isquare(primes[i]) - /* low */ 3) % segment_size;

  // segmented sieve of Eratosthenes
  for (int64_t low = 3; low <= limit; low += segment_size)
  {
    fill(sieve.begin(), sieve.end(), 1);
{'fraction_non_alphanumeric': 0.16578865819646732, 'fraction_numerical': 0.03222807561202355, 'mean_word_length': 3.42798353909465, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4569025', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1235, 'n_words': 341}