- All Contests
- ProjectEuler+
- Project Euler #196: Prime triplets

# Project Euler #196: Prime triplets

# Project Euler #196: Prime triplets

_{This problem is a programming version of Problem 196 from projecteuler.net}

Build a triangle from all positive integers in the following way:

Each positive integer has up to eight neighbours in the triangle.

A set of three primes is called a if one of the three primes has the other two as neighbours in the triangle.

For example, in the second row, the prime numbers and are elements of some prime triplet.

If row is considered, it contains two primes which are elements of some prime triplet, i.e. and .

If row is considered, it contains only one prime which is an element of some prime triplet: .

Define as the sum of the primes in row which are elements of any prime triplet.

Then and .

You are given that .

Find .

**Input Format**

The only line of each test file contains exactly two integers separated by a single space: and .

**Constraints**

**Output Format**

Output exactly one number that equals to .

**Sample Input 0**

```
8 9
```

**Sample Output 0**

```
97
```

**Sample Input 1**

```
9 10000
```

**Sample Output 1**

```
950007656
```