luogu#P5271. OwenOwl 不学车也不删库

    ID: 4225 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学数论Special Judge分治构造洛谷月赛

OwenOwl 不学车也不删库

Background

mcfx and ComeIntoPower like to make up problem backgrounds when they are bored. OwenOwl asked “buddy” zcysky why they did this, and “buddy” zcysky replied like this:

OwenOwl felt very upset, so one day he found J, and asked J to create 20010910 pointers to point the three of them to Azerbaijan to keep sunset company there.

While the three of them were touring Azerbaijan, OwenOwl smashed the car, and the repository was restored.

However, since mcfx and ComeIntoPower had previously posted too many nasty problems using the ID OwenOwl, OwenOwl’s reputation had already been damaged. To prove that the nasty ones were those two and not himself, OwenOwl made an easy “sign-in” problem.

Problem 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