#K47112. Twin Primes Finder
Twin Primes Finder
Twin Primes Finder
You are given two integers \(a\) and \(b\) representing the bounds of a range. Your task is to find all twin prime pairs of the form \((p, p+2)\) such that \(p\) is in the range \([a, b]\) and both \(p\) and \(p+2\) are prime numbers.
A twin prime pair is defined as two prime numbers that differ by 2, i.e. \(p\) and \(p+2\) are both prime. Note that even if \(p+2\) exceeds \(b\), the pair is valid as long as \(p\) lies in the range.
If no twin primes exist, your program should output No twin primes
.
inputFormat
The input is provided via stdin and consists of two space-separated integers:
- a: The starting integer of the range \( (1 \leq a \leq 10^6) \).
- b: The ending integer of the range \( (a \leq b \leq 10^6) \).
outputFormat
The output should be printed to stdout:
- If twin prime pairs exist, the first line must contain the total number of twin prime pairs found. Each subsequent line contains one twin prime pair in the format
(p, p+2)
. - If no twin prime pairs are found, print
No twin primes
(without quotes).
5 30
4
(5, 7)
(11, 13)
(17, 19)
(29, 31)
</p>