def digit_length(n): totlen = 0 n += not n while n > 0: klen = 1 k = 10 while n > k * k: k = k * k klen *= 2 n = n // k totlen += klen return totlen