OFFSET
1,3
EXAMPLE
The first number line below shows the perfect powers.
The second shows each positive integer k at position prime(k).
-1-----4-------8-9------------16----------------25--27--------32------36----
===1=2===3===4=======5===6=======7===8=======9==========10==11==========12==
MATHEMATICA
radQ[n_]:=n>1&&GCD@@Last/@FactorInteger[n]==1;
Table[NestWhile[#-1&, Prime[n], radQ[#]&], {n, 100}]
PROG
(PARI) a(n) = my(k=prime(n)-1); while (!(ispower(k) || (k==1)), k--); k; \\ Michel Marcus, Nov 25 2024
(Python)
from sympy import mobius, integer_nthroot, prime
def A378035(n):
def bisection(f, kmin=0, kmax=1):
while f(kmax) > kmax: kmax <<= 1
while kmax-kmin > 1:
kmid = kmax+kmin>>1
if f(kmid) <= kmid:
kmax = kmid
else:
kmin = kmid
return kmax
def f(x): return int(x-1+sum(mobius(k)*(integer_nthroot(x, k)[0]-1) for k in range(2, x.bit_length())))
m = (p:=prime(n)-1)-f(p)
return bisection(lambda x:f(x)+m, m, m) # Chai Wah Wu, Nov 25 2024
CROSSREFS
Restriction of A081676 to the primes.
Positions of last appearances are also A377283.
A version for squarefree numbers is A378032.
The union is A378253.
Terms appearing exactly once are A378355.
A069623 counts perfect powers <= n.
A076411 counts perfect powers < n.
A131605 lists perfect powers that are not prime powers.
KEYWORD
nonn
AUTHOR
Gus Wiseman, Nov 23 2024
STATUS
approved