Git Product home page Git Product logo

Comments (4)

kimwalisch avatar kimwalisch commented on August 30, 2024 1

Question:

Is it better to use [low, high] instead of [low, high[?

Answer:

In order to simplify the formula for min_index_2nd_prime it is best to use [low, high[. This was determined by printing and examining all minimum and maximum values using primecount.

from primecount.

kimwalisch avatar kimwalisch commented on August 30, 2024 1

It works! Implemented by #20.

from primecount.

kimwalisch avatar kimwalisch commented on August 30, 2024

Here I try to code the formulas above in C++. We need to add some more bounds checking to avoid array of bounds accesses:

  uint64_t min_index_1st_prime = pi[x_star] + 1;
  uint64_t min_1st_prime = primes[min_index_1st_prime];

  // x / (primes[i] * primes[i+1]) >= low
  // primes[i] * primes[i+1] <= x / low
  // primes[i] < sqrt(x / low)
  // primes[i+1] <= sqrt(x / low) || primes[i+1] >= sqrt(x / low)
  uint64_t x_div_low = x / low;
  uint64_t sqrt_low = min(isqrt(x_div_low), x13);
  uint64_t max_index_1st_prime = pi[sqrt_low];
  if (primes[max_index_1st_prime] < max_prime &&
      primes[max_index_1st_prime] * primes[max_index_1st_prime+1] > x_div_low)
    max_index_1st_prime -= 1;

  uint64_t min_2nd_prime = min(x / (high * primes[b]), max_prime);
  uint64_t min_index_2nd_prime = pi[min_2nd_prime] + 1;
  min_index_2nd_prime = max(min_index_2nd_prime, b + 1);
  min_2nd_prime = primes[min_index_2nd_prime];

  uint64_t max_2nd_prime = min(x / (low * primes[b]), isqrt(x / primes[b]));
  uint64_t max_index_2nd_prime = pi[max_2nd_prime];

from primecount.

kimwalisch avatar kimwalisch commented on August 30, 2024
x / (primes[b] * primes[q]) >= x^(1/3)

Hence we should start the segmentation with low = x^(1/3) using a segment size of e.g. z and the algorithm finishes when high = x^(1/2).

More accurately the algorithm finishes at:

min_index_1st_prime = pi[x_star] + 1;
high = x / (primes[min_index_1st_prime] * primes[min_index_1st_prime+1]) + 1

from primecount.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.