P27793 [洛谷] Enumerating Tuples
普及
题目描述

Problem Description

An $n$-tuple is a sequence consisting of $n$ elements. For example, $(1,1,2)$ is a 3-tuple, and $(233,254,277,123)$ is a 4-tuple.

Given $n$ and $k$, please output all $n$-tuples in lexicographical order, where the elements within the tuple are integers between $[1, k]$.

"Lexicographical order" means: prioritize sorting by the first element from smallest to largest, and if the first element is the same, sort by the second element from smallest to largest, and so on. Refer to the sample data for details.

Input Format

A single line containing two positive integers $n, k$.

Output Format

Several lines, each representing a tuple. The elements within the tuple are separated by spaces.

Sample Input and Output

Sample Input #1

2 3

Sample Output #1

1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

Sample Input #2

3 3

Sample Output #2

1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3
1 3 1
1 3 2
1 3 3
2 1 1
2 1 2
2 1 3
2 2 1
2 2 2
2 2 3
2 3 1
2 3 2
2 3 3
3 1 1
3 1 2
3 1 3
3 2 1
3 2 2
3 2 3
3 3 1
3 3 2
3 3 3

Notes

For $100\%$ of the data, $n \leq 5, k \leq 4$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 3
样例输出
1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3