AtCoder Regular Contest 152
D
Halftree
AtCoder
⌀ 2381
原题
← CE →
翻译中…

Problem Statement

翻译中…

We have an undirected graph with $N$ vertices numbered $0$ through $N-1$ and no edges at first. You may add edges to this graph as you like. When you are done with adding edges, the following operation will be performed once using a given integer $K$.

翻译中…
  • For each edge you have added, let $u$ and $v$ be its endpoints, and an edge will be added between two vertices $(u+K)$ $\mathrm{mod}$ $N$ and $(v+K)$ $\mathrm{mod}$ $N$. This edge will be added even if there is already an edge between these vertices, resulting in multi-edges.
翻译中…

For the given $N$ and $K$, find a set of edges that you should add so that the graph will be a tree after the operation. If there is no such set of edges, indicate that fact.

翻译中…

Constraints

翻译中…
  • $2\leq N\leq 2\times 10^5$
  • $1\leq K\leq N-1$
  • All values in the input are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N K

翻译中…

Output

翻译中…

If there is a set of edges that satisfies the requirement, let $M$ be the number of edges, and $a_i$ and $b_i$ be the two vertices connected by the $i$-th edge, and print a solution in the following format. Here, $0\leq M\leq N$ must hold, and all values must be integers. The edges may be printed in any order, as well as the endpoints of an edge.

翻译中…

M
a_1 b_1
a_2 b_2
\vdots
a_M b_M

翻译中…

If multiple solutions exist, any of them will be accepted.

翻译中…

If no set of edges satisfies the requirement, print -1.

翻译中…

样例

Input #1
5 2
Output #1
2
2 3
2 4
The operation will add the edges $4$-$0$ and $4$-$1$. Then, the graph will be a tree, so this is a legitimate output.
Input #2
2 1
Output #2
-1
There is no way to have a tree after the operation.
Input #3
7 1
Output #3
3
0 1
2 3
4 5
题目信息
题号
arc152_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。