Official

C - Comma Editorial by en_translator


We count the number for each position of comma.

The comma between the third- and fourth- least significant digit is written once for every number more than or equal to \(1000\). Therefore, the number of such commas is \(N-999\) if \(N\geq 1000\), otherwise \(0\).

Similarly, the comma between the sixth- and seventh- least significant digit is written once for every number more than equal to \(1000000\). Therefore, the number of such commas is \(N-999999\) if \(N\geq 1000000\), otherwise \(0\).

The overall number of commas can be counted similarly.

Sample Code (Python)

n=int(input())
ans=0

if n>=1000: ans+=n-999
if n>=1000000: ans+=n-999999
if n>=1000000000: ans+=n-999999999
if n>=1000000000000: ans+=n-999999999999
if n>=1000000000000000: ans+=n-999999999999999

print(ans)

posted:
last update: