Here is the translation of the programming task text from Russian to English: Generating a sequence of numbers with a digital root
Java
Hard
loops
Task «Here is the translation of the programming task text from Russian to English: Generating a sequence of numbers with a digital root»
Write a program that generates a sequence of integers, starting from a given number N, and continues to add to the last generated number its digital root (the sum of digits until a single digit remains). The program must generate exactly K numbers, starting from N. If at any step the number becomes greater than 10^9, the process stops and only what has been generated so far is output. Use only loops (for, while). Input: two integers N and K separated by a space. Output: a sequence of numbers separated by spaces.
Input Format
Two integers N and K, separated by a space. 1 ≤ N ≤ 1000, 1 ≤ K ≤ 10000.
Output Format
A sequence of K or fewer integers separated by a space. If the sequence is interrupted due to exceeding 10^9, output as many numbers as were obtained.
Examples
Example 1
INPUT
4
-1 -2 -3 -4
OUTPUT
Example 2
INPUT
99 4
OUTPUT
99 108 117 126
main.java