In mathematics, Sexy Primes are prime numbers that differ from each other by six. For example, the numbers 5 and 11 are both sexy primes, because they differ by 6. If p + 2 or p + 4 (where p is the lower prime) is also prime.
They can be grouped as:
- Sexy prime pairs : It is of the form (p, p + 6), where p and p + 6 are prime numbers.
Eg. (11, 17) is a sexy prime pairs.
- Sexy prime triplets : Triplets of primes (p, p + 6, p + 12) such that p + 18 is composite are called sexy prime triplets.
Eg. (7, 13, 19) is a Sexy prime triplets.
- Sexy prime quadruplets : Sexy prime quadruplets (p, p + 6, p + 12, p + 18) can only begin with primes ending in a 1 in their decimal representation (except for the quadruplet with p = 5).
Eg. (41, 47, 53, 59) is a Sexy prime quadruplets.
- Sexy prime quintuplets : In an arithmetic progression of five terms with common difference 6, one of the terms must be divisible by 5, because the two numbers are relatively prime. Thus, the only sexy prime quintuplet is (5, 11, 17, 23, 29); no longer sequence of sexy primes is possible.
Given a range of the form [L, R].The task is to print all the sexy prime pairs in the range.
Input : L = 6, R = 59 Output : (7, 13) (11, 17) (13, 19) (17, 23) (23, 29) (31, 37) (37, 43) (41, 47) (47, 53) (53, 59) Input : L = 1, R = 19 Output : (5, 11) (7, 13) (11, 17) (13, 19)
Sexy Prime within a range [L, R] can be generated using Sieve Of Eratosthenes. The idea is to generate bool array of Sieve and run a loop of i from L to R – 6 (inclusive) and check whether i and i + 6 are prime or not. If both are prime, print both number.
Below is the implementation of this approach:
(7, 13) (11, 17) (13, 19) (17, 23) (23, 29) (31, 37) (37, 43) (41, 47) (47, 53) (53, 59)
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Print the nearest prime number formed by adding prime numbers to N
- Quick ways to check for Prime and find next Prime in Java
- Find coordinates of a prime number in a Prime Spiral
- Print prime numbers with prime sum of digits in an array
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check whether the sum of prime elements of the array is prime or not
- Sum of each element raised to (prime-1) % prime
- Sum of prime numbers without odd prime digits
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Prime numbers after prime P with sum S
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime