GolfScript, 29 28 caracteres
{.{\.,{)1$\%},,-=}+2@?,?}:f;
Editar: se puede guardar un único carácter si restringimos la búsqueda a <2 ^ n, gracias a Peter Taylor por esta idea.
Versión previa:
{.{\)..,{)1$\%},,-@=!}+do}:f;
Un intento en GolfScript, ejecutar en línea .
Ejemplos:
13 f p # => 4096
14 f p # => 192
15 f p # => 144
El código contiene esencialmente tres bloques que se explican en detalle en las siguientes líneas.
# Calculate numbers of divisors
# .,{)1$\%},,-
# Input stack: n
# After application: D(n)
., # push array [0 .. n-1] to stack
{ # filter array by function
) # take array element and increase by one
1$\% # test division of n ($1) by this value
}, # -> List of numbers x where n is NOT divisible by x+1
, # count these numbers. Stack now is n xd(n)
- # subtracting from n yields the result
# Test if number of divisors D(n) is equal to d
# {\D=}+ , for D see above
# Input stack: n d
# After application: D(n)==d
{
\ # swap stack -> d n
D # calculate D(n) -> d D(n)
= # compare
}+ # consumes d from stack and prepends it to code block
# Search for the first number which D(n) is equal to d
# .T2@?,? , for T see above
# Input stack: d
# After application: f(d)
. # duplicate -> d d
T # push code block (!) for T(n,d) -> d T(n,d)
2@? # swap and calculate 2^d -> T(n,d) 2^d
, # make array -> T(n,d) [0 .. 2^d-1]
? # search first element in array where T(n,d) is true -> f(d)