Given a number n, count the total number of digits required to write all numbers from 1 to n.
Example 1:
Input: n = 13
Output: 17 
Explanation: There are total 17 
digits required to write all 
numbers from 1 to 13.
Example 2:
Input: n = 4
Output: 4
Explanation: There are total 4 
digits required to write all
numbers from 1 to 4.
Your Task:  
You dont need to read input or print anything. Complete the function totalDigits() which takes n as input parameter and returns the total number of digits required to write all numbers from 1 to n.
Expected Time Complexity: O(logn)
Expected Auxiliary Space: O(1)
Constraints:
1<= n <=100000

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3
class Solution:
    def totalDigits (ob, n):
        # code here 

Solutions:
class Solution:

	def totalDigits(ob, n):
		if n < 10:
			return n
		else:
			number = 9
			for i in range(10, n + 1):
				i = str(i)
				number += len(i)
			return number


class Solution:

	def totalDigits(ob, n):
		st = ''
		for i in range(1, n + 1):
			st = st + str(i)
		return len(st)


class Solution:

	def totalDigits(ob, n):
		sm = 0
		for i in range(1, n + 1):
			sm += len(str(i))
		return sm


class Solution:

	def totalDigits(ob, n):
		import math
		r = 0
		for i in range(1, n + 1):
			r += int(math.log10(i)) + 1
		return r


class Solution:

	def totalDigits(ob, n):
		c = 0
		for i in range(1, n + 1):
			if i < 10:
				c = c + 1
			else:
				s = str(i)
				c = c + len(s)
		return c


class Solution:

	def totalDigits(ob, n):
		init = n
		ans = sub = 0
		while init - sub > 0:
			ans += init - sub
			sub = sub * 10 + 9
		return ans


class Solution:

	def totalDigits(ob, n):

		def cd(i):
			i = str(i)
			return len(i)
		ans = 0
		for i in range(1, n + 1):
			ans += cd(i)
		return ans


class Solution:

	def totalDigits(ob, n):
		su = 0
		for i in range(1, n + 1):
			su += len(str(i))
		return su
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.totalDigits(n))


import math

class Solution:

	def totalDigits(ob, n):
		count = 0
		for i in range(1, n + 1):
			ans = str(i)
			count += len(ans)
		return count
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.totalDigits(n))


class Solution:

	def totalDigits(ob, n):
		d = str(n)
		d = len(d)
		c = d
		d = d - 1
		s = 0
		while d != 0:
			s += (10 ** d - 10 ** (d - 1)) * d
			d = d - 1
		e = (n - 10 ** (c - 1) + 1) * c
		return e + s
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.totalDigits(n))


import math

class Solution:

	def totalDigits(ob, n):
		sum = 0
		for i in range(1, n + 1):
			val = math.log10(i)
			sum += math.floor(val) + 1
		return sum
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.totalDigits(n))


class Solution:

	def totalDigits(ob, n):
		c = 0
		i = 1
		while i <= n:
			c += n - i + 1
			i *= 10
		return c


class Solution:

	def totalDigits(ob, n):
		c = 0
		for i in range(1, n + 1):
			j = str(i)
			c += len(j)
		return c


class Solution:

	def totalDigits(ob, n):
		d = 0
		t = n
		while t > 0:
			d += 1
			t = t // 10
		x = 0
		while n > 0:
			x += d * (n + 1 - 10 ** (d - 1))
			n = 10 ** (d - 1) - 1
			d -= 1
		return x


def lt(n):
	return len(str(n))

def ans(n, x):
	if n <= 9:
		x += n
		return x
	z = lt(n)
	if n - 1000 > 100 and z == lt(n - 1000):
		x += z * 1000
		return ans(n - 1000, x)
	elif n - 10 > 10 and z == lt(n - 10):
		x += z * 10
		return ans(n - 10, x)
	else:
		x += z
		return ans(n - 1, x)

class Solution:

	def totalDigits(ob, n):
		return ans(n, 0)


def ins(n):
	j = len(str(n))
	return j

class Solution:

	def totalDigits(ob, n):
		s = 0
		for i in range(1, n + 1):
			s = s + ins(i)
		return s


class Solution:

	def totalDigits(ob, n):
		a = [1] * n
		for i in range(1, n):
			a[i] += i
		str1 = ''.join(map(str, a))
		return len(str1)


import math

class Solution:

	def totalDigits(ob, n):
		digits = 0
		for i in range(1, n + 1):
			digits += len(str(i))
		return digits


class Solution:

	def totalDigits(ob, n):
		m = n
		c = 0
		while n != 0:
			n //= 10
			c = c + 1
		if c == 1:
			return m
		elif c == 2:
			return 9 + 2 * (m - 9)
		elif c == 3:
			return 9 + 2 * 90 + 3 * (m - 99)
		elif c == 4:
			return 9 + 2 * 90 + 3 * 900 + 4 * (m - 999)
		elif c == 5:
			return 9 + 2 * 90 + 3 * 900 + 4 * 9000 + 5 * (m - 9999)
		elif c == 6:
			return 9 + 2 * 90 + 3 * 900 + 4 * 9000 + 5 * 90000 + 6 * (m - 99999)


class Solution:

	def totalDigits(ob, n):
		count = 0
		i = 9
		if n <= 9:
			return n
		else:
			count = n
			while n > i:
				count += n - i
				i = i * 10 + 9
			return count


class Solution:

	def totalDigits(ob, n):
		l = len(str(n))
		ans = 0
		decrease = 0
		while l:
			ans += n - decrease
			decrease = decrease * 10 + 9
			l -= 1
		return ans


class Solution:

	def totalDigits(ob, n):
		s = ''
		sum = 0
		for i in range(1, n + 1):
			s = str(i)
			sum = sum + len(s)
		return sum