printРабочее место участника

printЗадачи

1497. Good or Bad?

Ограничения: время – 1s/2s, память – 64MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

Let the sum of the square of the digits of a positive integer `S_0` be represented by `S_1`. In a similar way, let the sum of the squares of the digits of `S_1` be represented by `S_2` and so on. If `S_i\ =\ 1` for some `i`, then the original integer `S_0` is said to be good number. A number, which is not good, is called bad number. For example 7 is a good number since `7\ →\ 49\ →\ 97\ →\ 130\ →\ 10\ →\ 1` and 4 is an bad number since `4\ →\ 16\ →\ 37\ →\ 58\ →\ 89\ →\ 145\ →\ 42\ →\ 20\ →\ 4`.
The input consists of several test cases, the number of which you are given in the first line of the input. Each test case consists of one line containing a single positive integer `N` smaller than `10^9`.
For each test case, you must print one of the following messages:
Case #`p`: `N` is a good number.
Case #`p`: `N` is a bad number.
Here `p` stands for the case number (starting from 1). You should print the first message if the number `N` is a good number. Otherwise, print the second message.

Sample Input

3
7
4
13

Sample Output

Case #1: 7 is a good number.
Case #2: 4 is a bad number.
Case #3: 13 is a good number.
loading