#K3256. Rectangular Grid Arrangements
Rectangular Grid Arrangements
Rectangular Grid Arrangements
You are given an integer \(N\) representing the number of students and a list of candidate products. Each candidate product represents a possible area for seating arrangements. Your task is to determine all valid rectangular grid arrangements (i.e. row and column pairs) such that the arrangement satisfies \(r \times c = N\). Note that an arrangement is only considered valid if \(N\) is present in the candidate products list.
If a valid arrangement exists, output each valid pair \((r, c)\) sorted in lexicographical order (first by \(r\), then by \(c\)). Otherwise, output NA
.
inputFormat
The input is provided via standard input (stdin) in two lines:
- The first line contains a single integer \(N\) (number of students).
- The second line contains space-separated integers representing candidate products.
outputFormat
If a valid arrangement exists (i.e. if \(N\) is among the candidate products), print each valid arrangement as two space-separated integers \(r\) and \(c\) on a separate line, sorted in lexicographical order. Otherwise, print NA
.
12
4 6 8 12
1 12
2 6
3 4
4 3
6 2
12 1
</p>