login
If n is prime then 1 else 2nd largest prime factor of n.
5

%I #23 Dec 16 2021 15:04:15

%S 1,1,1,2,1,2,1,2,3,2,1,2,1,2,3,2,1,3,1,2,3,2,1,2,5,2,3,2,1,3,1,2,3,2,

%T 5,3,1,2,3,2,1,3,1,2,3,2,1,2,7,5,3,2,1,3,5,2,3,2,1,3,1,2,3,2,5,3,1,2,

%U 3,5,1,3,1,2,5,2,7,3,1,2,3,2,1,3,5,2,3,2,1,3,7,2,3,2,5,2,1,7,3,5,1,3

%N If n is prime then 1 else 2nd largest prime factor of n.

%H Charles R Greathouse IV, <a href="/A087039/b087039.txt">Table of n, a(n) for n = 1..10000</a>

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/GreatestPrimeFactor.html">Greatest Prime Factor</a>

%F a(n) = A006530(A052126(n)) = A006530(n/A006530(n));

%F A087040(n) = a(A002808(n)).

%p A087039 := proc(n)

%p local pset ,t;

%p if isprime(n) or n= 1 then

%p 1;

%p else

%p pset := [] ;

%p for p in ifactors(n)[2] do

%p pset := [op(pset),seq(op(1,p),t=1..op(2,p))] ;

%p end do:

%p op(-2,sort(pset)) ;

%p end if;

%p end proc: # _R. J. Mathar_, Sep 14 2012

%t gpf[n_] := FactorInteger[n][[-1, 1]];

%t a[n_] := If[PrimeQ[n], 1, gpf[n/gpf[n]]];

%t Array[a, 105] (* _Jean-François Alcover_, Dec 16 2021 *)

%o (Haskell)

%o a087039 n | null ps = 1

%o | otherwise = head ps

%o where ps = tail $ reverse $ a027746_row n

%o -- _Reinhard Zumkeller_, Oct 03 2012

%o (Python)

%o from sympy import factorint

%o def a(n):

%o pf = factorint(n, multiple=True)

%o return 1 if len(pf) < 2 else pf[-2]

%o print([a(n) for n in range(1, 103)]) # _Michael S. Branicky_, Dec 16 2021

%Y Cf. A002808, A006530, A085392, A087040.

%Y Cf. A027746, A052126.

%K nonn,easy

%O 1,4

%A _Reinhard Zumkeller_, Aug 01 2003