A prime number is twin if at least one of or is prime and sexy if at least one of and is prime.
How many sexy twin primes (i.e. primes that are both twin and sexy) are there less than ? Express your answer as a positive integer in decimal notation; for example, 521495223. If your answer is in this form, your score for this problem will be , where is the actual answer to this problem. Otherwise, your score will be zero.
Problem 1259
Official solution
Solution:
Answer: 1462105
The Hardy-Littlewood conjecture states that given a set of integers, the number of integers such that is a prime for all is
where is the number of distinct residues of modulo and the term goes to 0 as goes to infinity. Note that for the 4 tuples of the form , , and using the approximation , we have
Applying this for the four sets , (and approximating and just taking the and terms), we get the approximate answer
One improvement we can make is to remove the double-counted tuples, in particular, integers such that , and one of is prime. Again by the Hardy-Littlewood conjecture, the number of such is approximately (using the same approximations)
Subtracting gives an estimate of about 1550000. Note that this is still an overestimate, as is actually about 20.7 and .
Here is the code that we used to generate the answer:
```
#include<iostream>
#include<cstring> // memset
using namespace std;
const int MAXN = 1e9;
bool is_prime[MAXN + 6];
int main(){
// Sieve of Eratosthenes
memset(is_prime, true, sizeof(is_prime));
is_prime[0] = is_prime[1] = false;
for (int i=2; i<MAXN + 6; i++){
if (is_prime*){
for (int j=2 * i; j < MAXN + 6; j += i){
is_prime[j] = false;
}
}
}
// Count twin sexy primes.
int ans = 1; // 5 is the only twin sexy prime < 6.
for (int i=6; i<MAXN; i++){
if (is_prime*
&& (is_prime[i-6] || is_prime[i+6])
&& (is_prime[i-2] || is_prime[i+2])) {
ans++;
}
}
cout << ans << endl;
return 0;
}
```