a494. CPE:2 the 9s (UVa 10922)

簡單CPE

時間限制 2000 ms ・ 記憶體限制 256 MB

題目描述

利用各位數字和判斷正整數 N 是否為 9 的倍數。若是,反覆將數字換成各位數字和,直到得到 9;所需的數字和計算層數稱為 9-degree。特別地,N = 9 的 9-degree 定義為 1。請判斷是否為 9 的倍數並計算其 9-degree。

輸入格式

每行一個正整數,最多 1000 位數。單獨的 0 表示輸入結束。

輸出格式

若為 9 的倍數,輸出 N is a multiple of 9 and has 9-degree D.;否則輸出 N is not a multiple of 9.。N 使用原輸入數字,D 為 9-degree,每筆一行。

題目來源:UVa 10922 — 2 the 9s,CPE 歷屆試題。 原題:https://onlinejudge.org/external/109/10922.pdf

範例測資

範例輸入 1

999999999999999999999
9
9999999999999999999999999999998
0

範例輸出 1

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.
請先登入後再提交程式碼

討論與題解

載入討論區…

更多