#110. 按规则生成数组模式
按规则生成数组模式
Array Pattern Generation
Background
Problem Description
Given an integer , create an array of length following a specific pattern. The pattern for is shown as: (spaces added to show the groups).
The array can be thought of as groups, each of length . Let be the array, and be its element at index .
For an element at index , let be the group index (0-indexed) and be the index within the group (0-indexed).
The value of is determined as follows:
- If , then .
- Otherwise (): Let . Let . If , then . Else (), then .
Input Format
Input is given from standard input in the following format.
An integer .
Output Format
Output is printed to standard output in the following format.
The generated array as a list of integers.
Sample
3
[0, 0, 1, 0, 2, 1, 3, 2, 1]
2
[0, 1, 2, 1]
4
[0, 0, 0, 1, 0, 0, 2, 1, 0, 3, 2, 1, 4, 3, 2, 1]
Sample Explanation
Constraints
Time limit: 1 second, Memory limit: 1024 KiB for each test case.