Arturo, 4949 45 bytes
f:$->n->(n>1)?[map[2,3,4,5]=>[+1+f[2..5|map=>[+1+f//n<=&]|min]->0
Port of xnor's 50-byte Python answer.
Arturo, 71 bytes
$->n->min map[0 1 3 2 7 6 4 3 8 9 12 27 16 81 6 5]=>[&+5*ceil log//n&4]
The formula in the OP.