{"problem":{"name":"D. Relatively Prime Graph","description":{"content":"Let's call an undirected graph $G = (V, E)$ _relatively prime_ if and only if for each edge $(v, u) \\in E$ $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge betw","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF1009D"},"statements":[{"statement_type":"Markdown","content":"Let's call an undirected graph $G = (V, E)$ _relatively prime_ if and only if for each edge $(v, u) \\in E$ $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to $|V|$.\n\nConstruct a _relatively prime_ graph with $n$ vertices and $m$ edges such that it is connected and it contains neither self-loops nor multiple edges.\n\nIf there exists no valid graph with the given number of vertices and edges then output _\"Impossible\"_.\n\nIf there are multiple answers then print any of them.\n\n## Input\n\nThe only line contains two integers $n$ and $m$ ($1 \\le n, m \\le 10^5$) — the number of vertices and the number of edges.\n\n## Output\n\nIf there exists no valid graph with the given number of vertices and edges then output _\"Impossible\"_.\n\nOtherwise print the answer in the following format:\n\nThe first line should contain the word _\"Possible\"_.\n\nThe $i$\\-th of the next $m$ lines should contain the $i$\\-th edge $(v_i, u_i)$ of the resulting graph ($1 \\le v_i, u_i \\le n, v_i \\neq u_i$). For each pair $(v, u)$ there can be no more pairs $(v, u)$ or $(u, v)$. The vertices are numbered from $1$ to $n$.\n\nIf there are multiple answers then print any of them.\n\n[samples]\n\n## Note\n\nHere is the representation of the graph from the first example: ![image](https://espresso.codeforces.com/501a835f442401d928aaaee2ff94c95a4900a18e.png)","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"[{\"iden\":\"statement\",\"content\":\"我们称一个无向图 $G = (V, E)$ 为 _互质图_，当且仅当对于每条边 $(v, u) \\\\in E$，都有 $\\\\gcd(v, u) = 1$（即 $v$ 和 $u$ 的最大公约数为 1）。如果某对顶点 $v$ 和 $u$ 之间没有边，则 $\\\\gcd(v, u)$ 的值无关紧要。顶点编号从 $1$ 到 $|V|$。\\n\\n请构造一个包含 $n$ 个顶点和 $m$ 条边的 _互质图_，要求该图连通，且不包含自环或重边。\\n\\n如果不存在满足条件的图，则输出 _\\\"Impossible\\\"_。\\n\\n如果存在多个答案，输出任意一个即可。\\n\\n输入仅一行，包含两个整数 $n$ 和 $m$（$1 \\\\leq n, m \\\\leq 10^5$）—— 分别表示顶点数和边数。\\n\\n如果不存在满足条件的图，则输出 _\\\"Impossible\\\"_。\\n\\n否则，请按以下格式输出答案：\\n\\n第一行输出单词 _\\\"Possible\\\"_。\\n\\n接下来的 $m$ 行中，第 $i$ 行输出第 $i$ 条边 $(v_i, u_i)$（$1 \\\\leq v_i, u_i \\\\leq n$，且 $v_i \\\\neq u_i$）。对于每对 $(v, u)$，最多只能出现一次 $(v, u)$ 或 $(u, v)$。顶点编号从 $1$ 到 $n$。\\n\\n如果存在多个答案，输出任意一个即可。\\n\\n第一个示例的图表示如下：\\n\\n\"},{\"iden\":\"input\",\"content\":\"输入仅一行，包含两个整数 $n$ 和 $m$（$1 \\\\leq n, m \\\\leq 10^5$）—— 分别表示顶点数和边数。\"},{\"iden\":\"output\",\"content\":\"如果不存在满足条件的图，则输出 _\\\"Impossible\\\"_。否则请按以下格式输出答案：第一行输出单词 _\\\"Possible\\\"_。接下来的 $m$ 行中，第 $i$ 行输出第 $i$ 条边 $(v_i, u_i)$（$1 \\\\leq v_i, u_i \\\\leq n$，且 $v_i \\\\neq u_i$）。对于每对 $(v, u)$，最多只能出现一次 $(v, u)$ 或 $(u, v)$。顶点编号从 $1$ 到 $n$。如果存在多个答案，输出任意一个即可。\"},{\"iden\":\"examples\",\"content\":\"输入\\n5 6\\n输出\\nPossible\\n2 5\\n3 2\\n5 1\\n3 4\\n4 1\\n5 4\\n\\n输入\\n6 12\\n输出\\nImpossible\"},{\"iden\":\"note\",\"content\":\"第一个示例的图表示如下： \"}]\n\n```json\n[{\"iden\":\"statement\",\"content\":\"我们称一个无向图 $G = (V, E)$ 为 _互质图_，当且仅当对于每条边 $(v, u) \\\\in E$，都有 $\\\\gcd(v, u) = 1$（即 $v$ 和 $u$ 的最大公约数为 1）。如果某对顶点 $v$ 和 $u$ 之间没有边，则 $\\\\gcd(v, u)$ 的值无关紧要。顶点编号从 $1$ 到 $|V|$。\\n\\n请构造一个包含 $n$ 个顶点和 $m$ 条边的 _互质图_，要求该图连通，且不包含自环或重边。\\n\\n如果不存在满足条件的图，则输出 _\\\"Impossible\\\"_。\\n\\n如果存在多个答案，输出任意一个即可。\\n\\n输入仅一行，包含两个整数 $n$ 和 $m$（$1 \\\\leq n, m \\\\leq 10^5$）—— 分别表示顶点数和边数。\\n\\n如果不存在满足条件的图，则输出 _\\\"Impossible\\\"_。\\n\\n否则，请按以下格式输出答案：\\n\\n第一行输出单词 _\\\"Possible\\\"_。\\n\\n接下来的 $m$ 行中，第 $i$ 行输出第 $i$ 条边 $(v_i, u_i)$（$1 \\\\leq v_i, u_i \\\\leq n$，且 $v_i \\\\neq u_i$）。对于每对 $(v, u)$，最多只能出现一次 $(v, u)$ 或 $(u, v)$。顶点编号从 $1$ 到 $n$。\\n\\n如果存在多个答案，输出任意一个即可。\\n\\n第一个示例的图表示如下：\\n\\n\"},{\"iden\":\"input\",\"content\":\"输入仅一行，包含两个整数 $n$ 和 $m$（$1 \\\\leq n, m \\\\leq 10^5$）—— 分别表示顶点数和边数。\"},{\"iden\":\"output\",\"content\":\"如果不存在满足条件的图，则输出 _\\\"Impossible\\\"_。否则请按以下格式输出答案：第一行输出单词 _\\\"Possible\\\"_。接下来的 $m$ 行中，第 $i$ 行输出第 $i$ 条边 $(v_i, u_i)$（$1 \\\\leq v_i, u_i \\\\leq n$，且 $v_i \\\\neq u_i$）。对于每对 $(v, u)$，最多只能出现一次 $(v, u)$ 或 $(u, v)$。顶点编号从 $1$ 到 $n$。如果存在多个答案，输出任意一个即可。\"},{\"iden\":\"examples\",\"content\":\"输入\\n5 6\\n输出\\nPossible\\n2 5\\n3 2\\n5 1\\n3 4\\n4 1\\n5 4\\n\\n输入\\n6 12\\n输出\\nImpossible\"},{\"iden\":\"note\",\"content\":\"第一个示例的图表示如下： \"}]\n```","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ with $ 1 \\leq n, m \\leq 10^5 $.  \nLet $ V = \\{1, 2, \\dots, n\\} $ be the set of vertices.  \nLet $ E \\subseteq \\binom{V}{2} $ be a set of undirected edges (no self-loops, no multiple edges).  \n\nA graph $ G = (V, E) $ is *relatively prime* if for every edge $ (u, v) \\in E $, $ \\gcd(u, v) = 1 $.  \nThe graph is *connected* if there exists a path between every pair of vertices in $ V $.\n\n**Constraints**  \n1. $ |E| = m $  \n2. $ G = (V, E) $ is connected  \n3. For all $ (u, v) \\in E $, $ \\gcd(u, v) = 1 $  \n4. $ u \\ne v $ for all $ (u, v) \\in E $\n\n**Objective**  \nDetermine whether there exists a set $ E $ satisfying the above constraints.  \n- If yes, output \"Possible\" followed by $ m $ distinct edges $ (u_i, v_i) \\in E $.  \n- If no, output \"Impossible\".","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF1009D","tags":["brute force","constructive algorithms","graphs","greedy","math"],"sample_group":[["5 6","Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4"],["6 12","Impossible"]],"created_at":"2026-03-03 11:00:39"}}