GolfScript, 29 28 caracteres
{.{\.,{)1$\%},,-=}+2@?,?}:f;
Edit: Um único caractere pode ser salvo se restringirmos a pesquisa a <2 ^ n, graças a Peter Taylor por essa ideia.
Versão anterior:
{.{\)..,{)1$\%},,-@=!}+do}:f;
Uma tentativa no GolfScript, execute online .
Exemplos:
13 f p # => 4096
14 f p # => 192
15 f p # => 144
O código contém essencialmente três blocos que são explicados em detalhes nas seguintes linhas.
# 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)