#C5445. First n Happy Numbers
First n Happy Numbers
First n Happy Numbers
You are given a positive integer n
. Your task is to compute the first n
happy numbers.
A happy number is defined by the following process: starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number either equals 1 (where it will remain), or it loops endlessly in a cycle that does not include 1. If it eventually reaches 1, the number is called happy. Otherwise, it is unhappy.
The transformation in each step can be expressed in \( \LaTeX \) as:
\[ S(n) = \sum_{i=1}^{k} d_i^2 \]where \(d_1, d_2, \dots, d_k\) are the digits of n
.
For example, the first 5 happy numbers are: 1, 7, 10, 13, and 19.
inputFormat
The input consists of a single line containing the positive integer n
(1 ≤ n ≤ 105).
outputFormat
Output the first n
happy numbers in one line, separated by a single space.
5
1 7 10 13 19
</p>