login
Largest perfect power <= n.
12

%I #38 Nov 06 2024 04:11:59

%S 1,1,1,4,4,4,4,8,9,9,9,9,9,9,9,16,16,16,16,16,16,16,16,16,25,25,27,27,

%T 27,27,27,32,32,32,32,36,36,36,36,36,36,36,36,36,36,36,36,36,49,49,49,

%U 49,49,49,49,49,49,49,49,49,49,49,49,64,64,64,64,64,64,64,64,64,64,64

%N Largest perfect power <= n.

%C a(n) = n if n is in A001597, otherwise a(n) = a(n-1). - _Robert Israel_, Dec 17 2015

%H Neven Sajko, <a href="/A081676/b081676.txt">Table of n, a(n) for n = 1..10000</a>

%F a(n) = n - A069584(n).

%p N:= 1000: # to get a(1) to a(N).

%p Powers:= {1,seq(seq(b^p, p=2..floor(log[b](N))),b=2..isqrt(N))}:

%p Powers:= sort(convert(Powers,list)):

%p j:= 1:

%p for i from 1 to N do

%p if i >= Powers[j+1] then j:= j+1 fi;

%p A[i]:= Powers[j];

%p od:

%p seq(A[i],i=1..N); # _Robert Israel_, Dec 17 2015

%t Array[SelectFirst[Range[#, 1, -1], Or[And[! PrimeQ@ #, GCD @@ FactorInteger[#][[All, -1]] > 1], # == 1] &] &, 72] (* _Michael De Vlieger_, Jun 14 2017 *)

%o (PARI) a(n) = {while(!ispower(n), n--; if (n==0, return (1))); n;} \\ _Michel Marcus_, Nov 04 2015

%o (Sage)

%o p = [i for i in (1..81) if i.is_perfect_power()]

%o r = [[p[i]]*(p[i+1]-p[i]) for i in (0..10)]

%o print([y for x in r for y in x]) # _Peter Luschny_, Jun 13 2017

%o (Python)

%o from sympy import mobius, integer_nthroot

%o def A081676(n):

%o def bisection(f,kmin=0,kmax=1):

%o while f(kmax) > kmax: kmax <<= 1

%o while kmax-kmin > 1:

%o kmid = kmax+kmin>>1

%o if f(kmid) <= kmid:

%o kmax = kmid

%o else:

%o kmin = kmid

%o return kmax

%o def f(x): return int(x-1+sum(mobius(k)*(integer_nthroot(x,k)[0]-1) for k in range(2,x.bit_length())))

%o m = n-f(n)

%o return bisection(lambda x:f(x)+m,m-1,n+1) # _Chai Wah Wu_, Nov 05 2024

%Y Cf. A001597, A069584.

%K nonn

%O 1,4

%A _Reinhard Zumkeller_, Mar 26 2003