簡單 時間限制:3 s記憶體限制:256 MB

Online Judge - 10922 - 2 the 9s

來源代碼:UVa
字串數學模擬CPE歷屆試題CPE一星
前往提交 ↓

A well-known trick to know if an integer N is a multiple of nine is to compute the sum S of its digits. If S is a multiple of nine, then so is N. This is a recursive test, and the depth of the recursion needed to obtain the answer on N is called the 9-degree of N.
Your job is, given a positive number N, determine if it is a multiple of nine and, if it is, its 9-degree.

輸入說明

The input is a file such that each line contains a positive number. A line containing the number 0 is the end of the input. The given numbers can contain up to 1000 digits.

輸出說明

資料格式說明

The output of the program shall indicate, for each input number, if it is a multiple of nine, and in case it is, the value of its nine-degree. See the sample output for an example of the expected formatting of the output.

輸入輸出範例

範例 1

範例輸入
999999999999999999999
9
9999999999999999999999999999998
0
範例輸出
999999999999999999999 is a multiple of 9 and has 9-degree 3.
9 is a multiple of 9 and has 9-degree 1.
9999999999999999999999999999998 is not a multiple of 9.

範例 2

範例輸入
1
18
99
81
0
範例輸出
1 is not a multiple of 9.
18 is a multiple of 9 and has 9-degree 1.
99 is a multiple of 9 and has 9-degree 2.
81 is a multiple of 9 and has 9-degree 1.

範例 3

範例輸入
99999999999
9000
1098
99999999998
0
範例輸出
99999999999 is a multiple of 9 and has 9-degree 3.
9000 is a multiple of 9 and has 9-degree 1.
1098 is a multiple of 9 and has 9-degree 2.
99999999998 is not a multiple of 9.
開啟討論
開啟紀錄

登入後即可撰寫程式、測試範例及提交解答。

登入