Calculating of integer logarithm base 2 is pretty easy in near any computer language - you just find the largest '1' in binary representation, and rest becomes zero.
Is is possible to do the same fast trick for other bases, for example 3, - calculate logarithm of base 3 or get the nearest integer from below what is correct 3n?