OFFSET
0,3
COMMENTS
If negative values were allowed then one could argue a(n) = 1-n from the name of A301573. - David A. Corneth, Nov 13 2023
LINKS
David A. Corneth, Table of n, a(n) for n = 0..10000
David A. Corneth, PARI program
FORMULA
a(n) > n^2 for n > 1. - David A. Corneth, Nov 13 2023
EXAMPLE
a(3) = 12 as 12 is the smallest positive integer that is 3 away from the closest perfect power (namely 9 = 3^2). - David A. Corneth, Nov 12 2023
PROG
(PARI) ispp(n) = {ispower(n) || n==1}; \\ A001597
f(n) = my(k=0); while(!ispp(n+k) && !ispp(n-k), k++); k; \\ A301573
a(n) = my(k=0); while (f(k) != n, k++); k; \\ Michel Marcus, Oct 29 2023
(PARI) \\ See PARI link
(Python)
from itertools import count
from sympy import perfect_power
def A366928(n): return next(m for m in count(0) if next(k for k in count(0) if perfect_power(m+k) or perfect_power(m-k) or m-k==1 or m+k==1) == n) # Chai Wah Wu, Nov 12 2023
CROSSREFS
KEYWORD
nonn
AUTHOR
Dmitry Kamenetsky, Oct 28 2023
EXTENSIONS
More terms from Michel Marcus, Oct 29 2023
STATUS
approved