OFFSET
1,4
COMMENTS
When factoring a number via trial division, one generally continues trying primes until it is certain that the remaining portion of n is prime. Sometimes, it is already clear that the remaining portion is prime before that portion is found; in this case, the last prime tried is the second to last prime factor.
LINKS
T. D. Noe, Table of n, a(n) for n = 1..10000
EXAMPLE
A(22) is 3, because after 3 is tried, it is clear that 11 is prime and no more factorization can be done.
A(18) is 3, because despite the largest prime factor (3) being obviously prime, it is not obviously the last factor until the first 3 is factored out.
MATHEMATICA
a[n_] := Module[{m = n, k = 1, p = 1, q}, While[q = Prime[k]; q^2 <= m, p = q; m = m/p^IntegerExponent[m, p]; k++]; p]; Array[a, 100] (* T. D. Noe, May 04 2011 *)
PROG
(JavaScript) prime(k), not shown, gives A000040[k].
function a(n) {
var k = 1;
while (Math.pow(prime(k), 2) <= n) {
var p = prime(k);
if (n % p == 0) {
n /= p;
} else {
k += 1;
}
}
return p;
}
CROSSREFS
KEYWORD
nonn
AUTHOR
Dan Uznanski, May 02 2011
STATUS
approved