2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
id: 5900f5151000cf542c510028
|
|
|
|
title: 'Problem 425: Prime connection'
|
2020-11-27 18:02:05 +00:00
|
|
|
challengeType: 5
|
2019-08-05 16:17:33 +00:00
|
|
|
forumTopicId: 302095
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: problem-425-prime-connection
|
2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --description--
|
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
Two positive numbers $A$ and $B$ are said to be connected (denoted by "$A ↔ B$") if one of these conditions holds:
|
2020-11-27 18:02:05 +00:00
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
1. $A$ and $B$ have the same length and differ in exactly one digit; for example, $123 ↔ 173$.
|
|
|
|
2. Adding one digit to the left of $A$ (or $B$) makes $B$ (or $A$); for example, $23 ↔ 223$ and $123 ↔ 23$.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
We call a prime $P$ a 2's relative if there exists a chain of connected primes between 2 and $P$ and no prime in the chain exceeds $P$.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
For example, 127 is a 2's relative. One of the possible chains is shown below:
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
$$2 ↔ 3 ↔ 13 ↔ 113 ↔ 103 ↔ 107 ↔ 127$$
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
However, 11 and 103 are not 2's relatives.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
Let $F(N)$ be the sum of the primes $≤ N$ which are not 2's relatives. We can verify that $F({10}^3) = 431$ and $F({10}^4) = 78\\,728$.
|
|
|
|
|
|
|
|
Find $F({10}^7)$.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --hints--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
`primeConnection()` should return `46479497324`.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
2021-07-29 18:14:09 +00:00
|
|
|
assert.strictEqual(primeConnection(), 46479497324);
|
2018-09-30 22:01:58 +00:00
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --seed--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
## --seed-contents--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
|
|
|
```js
|
2021-07-29 18:14:09 +00:00
|
|
|
function primeConnection() {
|
2020-09-15 16:57:40 +00:00
|
|
|
|
2018-09-30 22:01:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
primeConnection();
|
2018-09-30 22:01:58 +00:00
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --solutions--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
// solution required
|
|
|
|
```
|