Champernowne Verification

면접 대비

시간 제한1초메모리 제한2048 MB

요약
앞에 0이 없는 1 이상 10^9 이하의 정수 n이 1부터 k까지 이어 붙인 수인지 판별하고, 맞으면 k를, 아니면 -1을 출력한다.
난이도

보통10점 중 4점

유형
구현, 문자열, 완전 탐색, 수학
정답자
아직 제출이 없습니다

문제

The kthk^{\text{th}} Champernowne word is obtained by writing down the first kk positive integers and concatenating them together. For example, the 10th10^{\text{th}} Champernowne word is 1234567891012345678910.

Given a positive integer nn, determine if it is a Champernowne word, and if so, which word.

입력

The first line contains a single integer, nn (1≤n≤1091 \le n \le 10^9). nn will not have leading zeroes.

출력

If nn is the kthk^{\text{th}} Champernowne word, output kk. Otherwise, output −1-1.

예제4

  1. 예제 1

    입력
    123456789
    
    예상 출력
    9
    
  2. 예제 2

    입력
    1000000000
    
    예상 출력
    -1
    
  3. 예제 3

    입력
    11
    
    예상 출력
    -1
    
  4. 예제 4

    입력
    1324
    
    예상 출력
    -1