#K60632. Digit Sum Sequence Generation

    ID: 31130 Type: Default 1000ms 256MiB

Digit Sum Sequence Generation

Digit Sum Sequence Generation

You are given an initial non‐negative integer and a positive integer length. Your task is to generate a sequence of numbers where the first term is the initial number, and each subsequent term is the sum of the digits of the previous term. The sequence should have exactly length terms.

For example, given an initial number 12345 and length 3, the sequence is: [12345, 15, 6] because:

  • The sum of digits of 12345 is 1+2+3+4+5 = 15.
  • The sum of digits of 15 is 1+5 = 6.

Write a program that reads the input from standard input and outputs the sequence to standard output.

Note: If the sum of the digits results in a multi-digit number, continue summing the digits for the next term normally.

inputFormat

The input consists of two integers separated by space:

  • initial_number: The starting non-negative integer.
  • length: A positive integer representing the number of terms in the sequence.

These values are provided on a single line from standard input.

outputFormat

Output the generated sequence as space-separated integers on a single line to standard output.

## sample
12345 3
12345 15 6