
시간복잡도:
O(logN), 공간복잡도:O(1)
- [ x ] 1회
- 2회
- 3회
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
if(n<10){
System.out.println(n);
return;
}
long count = 0;
int base = 1; //해당 자릿수 시작값
int digit = 1;
while(base*10<=n){
count+=(long)(base*9)*digit;
base*=10;
digit++;
}
// 마지막 자릿수 구간
count+=(long)(n-base+1)*digit;
System.out.println(count);
}
}
