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.
%I A301573 #37 Nov 12 2023 21:52:53 %S A301573 1,0,1,1,0,1,2,1,0,0,1,2,3,3,2,1,0,1,2,3,4,4,3,2,1,0,1,0,1,2,2,1,0,1, %T A301573 2,1,0,1,2,3,4,5,6,6,5,4,3,2,1,0,1,2,3,4,5,6,7,7,6,5,4,3,2,1,0,1,2,3, %U A301573 4,5,6,7,8,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,9,8,7,6,5,4,3,2,1,0 %N A301573 Distance to nearest perfect power n^k, k>=2 (A001597). %C A301573 Differs from A061670 at n=36. %C A301573 Let b(n) be the smallest t such that a(t) = n. Initial values of b(n) are 1, 0, 6, 12, 20, 41, 42, 56, 72, 90, 110, 155, 156, 182, 270, 271, 272, 306, 379, ... %C A301573 The b(n) sequence determines the positions of certain humps of a(n) sequence. See scatterplot of this sequence in order to observe general structure of a(n). %C A301573 b(n) is A366928(n). - _Dmitry Kamenetsky_, Oct 28 2023 %H A301573 Altug Alkan, <a href="/A301573/b301573.txt">Table of n, a(n) for n = 0..10000</a> %H A301573 <a href="/index/Di#distance_to_the_nearest">Index entries for sequences related to distance to nearest element of some set</a> %F A301573 a(n) = 0 iff n belongs to A001597. %e A301573 a(20) = a(21) = 4 because 16 is the nearest perfect power to 20 and 25 is the nearest perfect power to 21 (20 - 16 = 25 - 21 = 4). %e A301573 a(36) = 0 because 36 is a square. %o A301573 (PARI) isA001597(n) = {ispower(n) || n==1} %o A301573 a(n) = {my(k=0); while(!isA001597(n+k) && !isA001597(n-k), k++); k;} %o A301573 (Python) %o A301573 from itertools import count %o A301573 from sympy import perfect_power %o A301573 def A301573(n): return next(k for k in count(0) if perfect_power(n+k) or perfect_power(n-k) or n-k==1 or n+k==1) # _Chai Wah Wu_, Nov 12 2023 %Y A301573 Cf. A001597, A061670, A366928. %K A301573 nonn %O A301573 0,7 %A A301573 _Rémy Sigrist_ and _Altug Alkan_, Mar 23 2018