The sequence 1 2 2 3 3 3 ...

Report a typo

Wow! This problem is kind of tricky. If you're ready to put your thinking cap on, brace yourself, and good luck! Otherwise, you can skip it for now and return any time later.

Write a program that prints a part of the following sequence 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 ... (the number of repetitions is equal to the respective number). Input is a positive integer n – the number of the elements of the sequence that the program should print. Output the sequence of numbers, written in a single line, separated by spaces.

For example, if n is 7, the program should output 1 2 2 3 3 3 4 (seven numbers).

Note that a space at the end of the output line does not affect the result. Pay attention to the numbers.

Sample Input 1:

7

Sample Output 1:

1 2 2 3 3 3 4
Write a program in Kotlin
fun main() {
// put your code here
}
___

Create a free account to access the full topic