OFFSET
1,2
LINKS
Antti Karttunen, Table of n, a(n) for n = 1..16384
EXAMPLE
There are four divisors of 15: (1,3,5,15). There are two divisors, 3 and 5, that are nearest 4. Since there is a tie (4 is equidistant from 3 and 5), we take the smaller divisor, 3, so a(15) = 3.
MAPLE
A138224 := proc(n) if n = 1 then RETURN(1); fi; t := numtheory[tau](n) ; dvs := sort(convert(numtheory[divisors](n), list)) ; a := op(1, dvs) ; for i from 2 to nops(dvs) do if abs(op(i, dvs) - t) < abs(a-t) then a := op(i, dvs) ; fi; od: a ; end: seq(A138224(n), n=1..120) ; # R. J. Mathar, Jul 20 2009
MATHEMATICA
nd[n_]:=Module[{div=Divisors[n]}, Nearest[div, Length[div]][[1]]]; Array[ nd, 110] (* Harvey P. Dale, Jun 17 2018 *)
PROG
(PARI) A138224(n) = { my(pd=0, u=numdiv(n)); fordiv(n, d, if(d>u, return(if((d-u)<(u-pd), d, pd))); pd=d); (pd); }; \\ Antti Karttunen, Apr 01 2021
CROSSREFS
KEYWORD
nonn
AUTHOR
Leroy Quet, Mar 06 2008
EXTENSIONS
Extended beyond a(15) by R. J. Mathar, Jul 20 2009
STATUS
approved