Halftree

AtCoder
IDarc152_d
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
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
API Response (JSON)
{
  "problem": {
    "name": "Halftree",
    "description": {
      "content": "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 operatio",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc152_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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 operatio...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments