UVA-10591 - Happy Number

  • UVa Online Judge 解題結果請於 Submit 後,參閱 uHunt
  • 如果你有任何建議與指教,歡迎於下方留言一起討論喔!
  • 本題選為「20171219 大學程式能力檢定 CPE」題目。
  • 相同題目:ZOJ-d442

題意概要

讓我們定義正整數 中每個數字的平方和為 。以相同的方法我們定義 中每個數字的平方和為 ,並依此類推。假如有某個 () 則我們說 是一個 Happy number。如果某一個數不是 Happy number,那他就是一個 Unhappy number。例如: 是一個 Happy number,因為 。但是 是一個 Unhappy number,因為 ,永遠也無法產生


Input

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 smaller than .


Output

For each test case, you must print one of the following messages:

Case #p: N is a Happy number.
Case #p: N is an Unhappy number.

Here stands for the case number (starting from ). You should print the first message if the number is a happy number. Otherwise, print the second line.


Sample Input

3
7
4
13

Sample Output

Case #1: 7 is a Happy number.
Case #2: 4 is an Unhappy number.
Case #3: 13 is a Happy number.
profile-image
David Lu
Hello, I'm David Lu. I am a graduate student in Department of Computer Science at National Chiao Tung University, Taiwan. I am in the Networking and Sensing Systems (NSS) Lab at NCTU. If you have any question, please feel free to contact with me.
comments powered by Disqus