#P5271. OwenOwl 不学车也不删库

OwenOwl 不学车也不删库

Description

Let pp be a prime number.

You are given an undirected complete graph with pkp^k vertices (there is an undirected edge between any two vertices). The vertices are labeled from 00 to pk1p^k-1.

Now you need to find some complete subgraphs on pp vertices such that every edge in the original graph belongs to one and only one of these complete subgraphs.

Obviously, the number of complete subgraphs you need to find is pk(pk1)/2p(p1)/2\frac{p^k(p^k-1)/2}{p(p-1)/2}. You can see that this expression is always an integer.

Input Format

One line containing two positive integers p,kp, k.

Output Format

If there is no solution, output one line NO.

Otherwise, output one line YES, then output pk(pk1)/2p(p1)/2\frac{p^k(p^k-1)/2}{p(p-1)/2} lines. Each line contains pp numbers, representing the vertex labels of one complete subgraph you found.

You may output any valid solution in any order.

2 2
YES
0 1
2 0
3 0
1 2
1 3
3 2
3 1
YES
0 1 2

Hint

For 10%10\% of the testdata, k1k \le 1.

For 50%50\% of the testdata, k2k \le 2.

Another 20%20\% of the testdata has p=2p = 2.

For 100%100\% of the testdata, kk is a positive integer, pp is prime, and 2pk20002 \le p^k \le 2000.

In addition, the total output size is guaranteed not to exceed 2MB, but you should still pay attention to the time spent on output.

Translated by ChatGPT 5