Number of numbers which can be represented as the sum of two distinct primes ?

Правка en1, от prac64, 2018-07-16 07:22:49

I saw a question somewhere, which asked to find the number of distinct numbers which can be represented as sum of two distinct primes. T=10000,N=10000000, the question felt impossible, so after attempting for a while, I saw the editorial, the solution was incorrect and poorly written.

If we did not have distinctness constraint, we could use goldbach conjecture and also mark p+2 as true(where p is prime) in a sieve and find the ans, but here we want only distinct sum of distinct primes, above approach would include 4(2+2) in the answers, which is not okay.

Even though the question is probably not solvable for the given values(i.e. n=1e7), what would be your best algorithm for this problem. And upto what n could it solve the problem for ? (1e3? 1e4? 1e5 ? 1e6 ? 1e7?)

Is it possible to answer more queries ? (lets say the limit comes from space complexity, so we can answer more queries)

sample cases n=4 ans=0

n=5 ans=1 (5=2+3)

n=9 ans=4 (5=2+3,7=5+2,8=5+3,9=7+2) (6=3+3 is not valid because the primes are not distinct)

Thank you codeforces !!

Теги math, primes, sieve

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский prac64 2018-07-16 07:22:49 1158 Initial revision (published)