Cookie Monster Concussion

면접 대비

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

요약
10^18 이하의 수가 주어지면 각 자리 숫자의 합을 한 자리가 될 때까지 반복해서 구한 뒤 그 값을 출력한다.
난이도

쉬움10점 중 2점

유형
수학, 구현, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Oh no! Cookie Monster got a concussion after hitting his head on his desk (he couldn't wrap his head around a bug while coding). He is currently in bed recovering, but he is starting to feel hungry and wants some cookies. However, he gets indigestion when he eats an amount of cookies that is not a multiple of 99. Due to his concussion, he temporarily forgot how to divide by 99. Luckily, he remembers a cool algorithm to determine if a number is a multiple of 99.

The algorithm is to sum the digits of the number in question, and checking if the sum is 99. If the number is greater than or equal to 1010, then repeat the process on the sum. If and only if the sum of the digits is 99, then the number is a multiple of 99. Here are a few examples of the algorithm with multiples of 99. \begin{align*} 81 &\rightarrow 8 + 1 = 9 \\ 117 &\rightarrow 1 + 1 + 7 = 9 \\ 1251 &\rightarrow 1 + 2 + 5 + 1 = 9 \\ 99 &\rightarrow 9 + 9 = 18 \rightarrow 1 + 8 = 9 \end{align*} The following are not multiples of 99. \begin{align*} 51 &\rightarrow 5 + 1 = 6 \\ 219 &\rightarrow 2 + 1 + 9 = 12 \rightarrow 1 + 2 = 3\\ 2714 &\rightarrow 2 + 7 + 1 + 4 = 14 \rightarrow 1 + 4 = 5 \end{align*} Given the number of cookies Cookie Monster wants to eat, your task is to determine if Cookie Monster should eat that many cookies.

입력

The first and only line of input will contain a single integer 1≤C≤10181 \leq C \leq 10^{18} representing the number of cookies that Cookie Monster wants to eat.

출력

Print the single-digit integer that Cookie Monster's algorithm outputs for the given number.

예제5

  1. 예제 1

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

    입력
    51
    
    예상 출력
    6
    
  3. 예제 3

    입력
    117
    
    예상 출력
    9
    
  4. 예제 4

    입력
    219
    
    예상 출력
    3
    
  5. 예제 5

    입력
    2714
    
    예상 출력
    5