#B3621. Lexicographical Tuples Generation
Lexicographical Tuples Generation
Lexicographical Tuples Generation
Given two integers \(n\) and \(k\), generate all \(n\)-tuples where each element is an integer in the range \([1, k]\). The \(n\)-tuples must be printed in lexicographical order. For example, a tuple is defined as a sequence of \(n\) elements, e.g., \((1,1,2)\) is a 3-tuple and \((233,254,277,123)\) is a 4-tuple.
Lexicographical order means that tuples are ordered primarily by the first element, then by the second, and so on. For instance, when \(n=2\) and \(k=2\), the valid tuples in lexicographical order are:
1 1 1 2 2 1 2 2
Write a program to output all such \(n\)-tuples.
inputFormat
The input consists of two space-separated integers:
- \(n\): the length of each tuple
- \(k\): the maximum value for each element (each element is in \([1, k]\))
outputFormat
Output all \(n\)-tuples in lexicographical order. Each tuple should be printed on a separate line with its elements separated by a single space.
sample
1 3
1
2
3
</p>