35 lines
1.2 KiB
Text
35 lines
1.2 KiB
Text
Twin primes are pairs of natural numbers (P<sub>1</sub> and P<sub>2</sub>) that satisfy the following:
|
|
|
|
::# P<sub>1</sub> and P<sub>2</sub> are primes
|
|
::# P<sub>1</sub> + '''2''' = P<sub>2</sub>
|
|
|
|
|
|
;Task:
|
|
Write a program that displays the number of <b>pairs of twin primes</b> that can be found <u>under</u> a user-specified number
|
|
<br>(P<sub>1</sub> < <i>user-specified number</i> & P<sub>2</sub> < <i>user-specified number</i>).
|
|
|
|
|
|
;Extension:
|
|
::# Find all twin prime pairs under 100000, 10000000 and 1000000000.
|
|
::# What is the time complexity of the program? Are there ways to reduce computation time?
|
|
|
|
|
|
;Examples:
|
|
<pre>
|
|
> Search Size: 100
|
|
> 8 twin prime pairs.
|
|
</pre>
|
|
|
|
<pre>
|
|
> Search Size: 1000
|
|
> 35 twin prime pairs.
|
|
</pre>
|
|
|
|
|
|
;Also see:
|
|
* The OEIS entry: [[oeis:A001097|A001097: Twin primes]].
|
|
* The OEIS entry: [[oeis:A167874|A167874: The number of distinct primes < 10^n which are members of twin-prime pairs]].
|
|
* The OEIS entry: [[oeis:A077800|A077800: List of twin primes {p, p+2}, with repetition]].
|
|
* The OEIS entry: [[oeis:A007508|A007508: Number of twin prime pairs below 10^n]].
|
|
<br><br>
|
|
|