Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ValeryVerkhoturov/9a140b593f44aa401b4de432ef57367f to your computer and use it in GitHub Desktop.

Select an option

Save ValeryVerkhoturov/9a140b593f44aa401b4de432ef57367f to your computer and use it in GitHub Desktop.
private List<PrimeNumber> primesBetween(@Nullable Long from, @NonNull Long to) {
if (from == null || from < MIN_PRIME_VALUE)
from = MIN_PRIME_VALUE;
Map<Long, Boolean> primes = new HashMap<>();
for (long i = from; i <= to; ++i) {
Boolean isPrime = primes.get(i);
if (isPrime == null || isPrime)
for (long j = MIN_PRIME_VALUE; j <= to; ++j) {
primes.put(i * j, false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment