%I #31 Jul 01 2024 14:36:18
%S 1,2,8,19,20,37,61,128,217,271,398,919,1519,1520,2978,3170,4220,4447,
%T 4681,5677,5941,6488,8269,9920,10621,12481,16651,17558,22448,26227,
%U 29701,34028,34669,35317,35971,56719,60920,61777,74419,75367,80197,88238,93458
%N Numbers in a hexagonal tiling (seen as concentric rings) which have exactly three neighbors whose difference from it is prime.
%C A hexagonal tile with number 1 is surrounded by a ring of six hexagonal tiles, starting on the right and numbering the tiles 2 to 7 in a counterclockwise direction. New rings are added in the same fashion, with the next rings being numbered 8 to 19, 20 to 37, and so on (see the illustration below). By finding the difference between tile n and each of its six neighbors we shall define PD(n) to be the number of those differences which are prime. For example, working counter-clockwise around tile 8 the differences are 12, 13, 1, 6, 11, and 29. So PD(8)=3. In the same way, the differences around tile 17 are 1, 10, 11, 1, 16, and 17, hence PD(17) = 2. It can be shown that the maximum value of PD(n) is 3. This sequence lists all tiles for which PD(n)=3 in ascending order.
%C It can be shown that only the first and last tile of every ring need to be considered.
%H Antoine Mathys, <a href="/A372223/b372223.txt">Table of n, a(n) for n = 1..10000</a>
%H Project Euler, <a href="https://projecteuler.net/problem=128">Problem 128 - Hexagonal Tile Differences</a>.
%e For tile 1, the differences are 1,2,3,4,5,6, thus PD(1)=3 and a(1)=1.
%e For tile 2, the differences are 6,7,1,1,5,17, thus PD(2)=3 and a(2)=2.
%e For tile 3, the differences are 6,7,8,1,2,1, thus PD(3)=2 and 3 is not in the list.
%e Similarly, we see that PD(4)=2, PD(5)=0, PD(6)=2, PD(7)=2, and PD(8)=3. Thus the next term is a(3)=8.
%e 26--25--24--23
%e / \
%e 27 12--11--10 22
%e / / \ \
%e 28 13 4---3 9 21
%e / / / \ \ \
%e 29 14 5 1 2 8 20
%e \ \ \ / / /
%e 30 15 6---7 19 37
%e \ \ / /
%e 31 16--17--18 36
%e \ /
%e 32---33--34--35
%e .
%o (C++)
%o #include <iostream>
%o bool is_prime (long n)
%o {
%o if (n < 2) return false;
%o if ((n == 2) || (n == 3)) return true;
%o if ((n % 6 != 1) && (n % 6 != 5)) return false;
%o for (long x = 1; (6 * x - 1) * (6 * x - 1) <= n; x++) {
%o if (n % (6 * x - 1) == 0) return false;
%o if ((6 * x + 1) * (6 * x + 1) > n) break;
%o if (n % (6 * x + 1) == 0) return false;
%o }
%o return true;
%o }
%o int main ()
%o {
%o constexpr long MAX_INDEX = 10000;
%o if (MAX_INDEX >= 1) std::cout << "1 1\n";
%o if (MAX_INDEX >= 2) std::cout << "2 2\n";
%o // We count the rings starting at 0 (the one containing 1)
%o for (long r = 2, index = 2; index < MAX_INDEX; r++) {
%o if (!is_prime (6 * r - 1)) continue;
%o // first cell
%o if (!is_prime (6 * r + 1)) goto LAST;
%o if (!is_prime (12 * r + 5)) goto LAST;
%o index++;
%o std::cout << index << " " << 3 * (r - 1) * r + 2 << '\n';
%o if (index == MAX_INDEX) break;
%o LAST:
%o // last cell
%o if (!is_prime (6 * r + 5)) continue;
%o if (!is_prime (12 * (r - 1) + 5)) continue;
%o index++;
%o std::cout << index << " " << 3 * r * (r + 1) + 1 << '\n';
%o }
%o }
%K nonn
%O 1,2
%A _Antoine Mathys_, Apr 22 2024