cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A345293 a(n) is the first number on the n-th layer in a layered square spiral of primes.

This page as a plain text file.
%I A345293 #9 Jul 01 2021 23:44:07
%S A345293 2,73,149,211,307,467,659,839,1061,1319,1511,1697,1949,2129,2381,2677,
%T A345293 2819,3137,3307,3407,3559,3907,4079,4253,4591,4877,5087,5443,5531,
%U A345293 5683,5923,6221,6659,6791,6997,7393,7603,8111,8297,8641,8887,9029,9377,9461,9749
%N A345293 a(n) is the first number on the n-th layer in a layered square spiral of primes.
%C A345293 The first prime, 2, is placed at the origin with Cartesian coordinates of (0, 0, 0) and the second prime, 3, is placed at (1, 0, 0). The m-th prime (m >= 3) is placed by moving one unit forward in the direction from the (m-2)-th prime to the (m-1)-th prime, if the next prime is not a twin prime of the current one; otherwise, by turning 90 degrees counterclockwise and moving one unit forward. When it comes to a spot already occupied by another number, the prime is moved up one layer above the number.
%e A345293 First layer starts from 2 and second layer from 73.
%e A345293   59<--53<--47<--43<--41
%e A345293    |                   |
%e A345293   61   11<---7<---5   37     137<-131<-127<-113<-109<-107
%e A345293    |    |         |    |      |                        |
%e A345293   67   13    2--->3   31     139                      103
%e A345293    |    |              |                               |
%e A345293   71   17-->19-->23-->29      73-->79-->83-->89-->97->101
%o A345293 (Python)
%o A345293 from sympy import prime, nextprime
%o A345293 print(2); d1 = 0; L = [0, 0, 0]; L1 = []
%o A345293 for i in range(1, 1501):
%o A345293     p = prime(i); np = nextprime(p); d = (d1 + 1)%4 if np - p == 2 else d1
%o A345293     L[0] += 1 if d == 0 else -1 if d == 2 else 0
%o A345293     L[1] += 1 if d == 1 else -1 if d == 3 else 0
%o A345293     if L in L1: L[2] += 1; print(np)
%o A345293     L1.append([L[0], L[1], L[2]]); d1 = d
%Y A345293 Cf. A063826, A136626.
%K A345293 nonn
%O A345293 1,1
%A A345293 _Ya-Ping Lu_, Jun 13 2021