시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 1872 691 591 39.905%

문제

양의 정수 N의 디지털 루트를 구하려면 N을 이루고 있는 모든 자리수를 더해야 한다. 이 때, 더한 값이 한 자리 숫자라면, 그 수가 N의 디지털 루트가 된다. 두 자리 이상 숫자인 경우에는 다시 그 수를 이루고 있는 모든 자리수를 더해야 하며, 한 자리 숫자가 될 때 까지 반복한다.

24의 디지털 루트를 구해보자. 2+4=6이다. 6은 한 자리 숫자이기 때문에, 24의 디지털 루트는 6이 된다. 39의 경우에는 3+9=12이기 때문에, 한 번 더 더해야 한다. 따라서, 1+2=3이 디지털 루트가 된다.

양의 정수 N이 주어졌을 때, 그 수의 디지털 루트를 구하는 프로그램을 작성하시오.

입력

한 줄에 하나씩 양의 정수가 주어진다. 입력의 마지막 줄은 0으로 나타낸다.  수는 최대 1000자리이다.

출력

입력으로 주어진 양의 정수의 디지털 루트를 한 줄에 하나씩 주어진 순서대로 출력한다.

예제 입력 1

24
39
0

예제 출력 1

6
3
W3sicHJvYmxlbV9pZCI6IjYzNzgiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWI1MTRcdWM5YzBcdWQxMzggXHViOGU4XHVkMmI4IiwiZGVzY3JpcHRpb24iOiI8cD5cdWM1OTFcdWM3NTggXHVjODE1XHVjMjE4IE5cdWM3NTggXHViNTE0XHVjOWMwXHVkMTM4IFx1YjhlOFx1ZDJiOFx1Yjk3YyBcdWFkNmNcdWQ1NThcdWI4MjRcdWJhNzQgTlx1Yzc0NCBcdWM3NzRcdWI4ZThcdWFjZTAgXHVjNzg4XHViMjk0IFx1YmFhOFx1YjRlMCBcdWM3OTBcdWI5YWNcdWMyMThcdWI5N2MgXHViMzU0XHVkNTc0XHVjNTdjIFx1ZDU1Y1x1YjJlNC4gXHVjNzc0IFx1YjU0YywgXHViMzU0XHVkNTVjIFx1YWMxMlx1Yzc3NCBcdWQ1NWMgXHVjNzkwXHViOWFjIFx1YzIyY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