P28955 [洛谷] OwenOwl Doesn't Learn to Drive Nor Delete Databases
提高+
题目描述

Problem Background

Deities mcfx and ComeIntoPower often concoct problem backgrounds for no reason. OwenOwl inquired the reason from zcysky, who responded thus:

OwenOwl was quite frustrated and one day sought the deity J to create 20010910 pointers to send the three of them to Azerbaijan to accompany sunset.

While they toured Azerbaijan, OwenOwl smashed the car and restored the database.

However, due to the numerous toxic problems previously released under the ID OwenOwl by mcfx and ComeIntoPower, OwenOwl's reputation had already been tarnished. To prove that the toxicity was from the two of them, not himself, OwenOwl decided to create an easy problem.

Problem Description

Let $p$ be a prime number.

You have an undirected complete graph with $p^k$ vertices (each pair of vertices is connected by an undirected edge), labeled from $0$ to $p^k-1$.

You need to find some complete subgraphs of $p$ vertices each, such that every edge in the original graph belongs to exactly one of these subgraphs.

Clearly, the number of such subgraphs you need to find is $\frac{p^k(p^k-1)/2}{p(p-1)/2}$, which is always an integer.

Input Format

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

Output Format

If there is no solution, output a single line NO.

Otherwise, output a line YES, followed by $\frac{p^k(p^k-1)/2}{p(p-1)/2}$ lines, each containing $p$ numbers representing the vertex labels of one of the complete subgraphs.

Output any valid solution in any order.

Sample Input and Output

Sample Input #1

2 2

Sample Output #1

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

Sample Input #2

3 1

Sample Output #2

YES
0 1 2

Notes/Hints

For $10\%$ of the data, $k \le 1$;

For $50\%$ of the data, $k \le 2$;

For an additional $20\%$ of the data, $p = 2$;

For $100\%$ of the data, $k$ is a positive integer, $p$ is a prime number, and $2 \le p^k \le 2000$.

Additionally, ensure that the total output does not exceed 2MB, but please still be mindful of the time taken for output.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

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