Monday, November 13, 2017

Print 1 to N - Digits Count

A positive integer N is passed as the input. If we print all the numbers from 1 to N continuosly, the program must find the number of characters(digits) C printed and print the count C as the output.

Input Format:
The first line contains N.

Output Format:
The first line contains C.

Boundary Conditions: 1 <= N <= 9999999

Example Input/Output 1:
Input:
2
Output:
2
Explanation:
We print 12 and hence the total number of characters is 2.

Solution:
n,c,i=int(input()),0,1
while i<=n:
    c+=n-i+1
    i*=10 
print(c)
Share: