D. Relatively Prime Graph

Let's call an undirected graph G=(V,E)G=(V,E) relatively prime if and only if for each edge (v,u)E(v,u)∈E  GCD(v,u)=1GCD(v,u)=1 (the greatest common divisor of vv and uu is 11). If there is no edge between some pair of vertices vv and uu then the value of GCD(v,u)GCD(v,u) doesn't matter. The vertices are numbered from 11 to |V||V|.

Construct a relatively prime graph with nn vertices and mm edges such that it is connected and it contains neither self-loops nor multiple edges.

If there exists no valid graph with the given number of vertices and edges then output "Impossible".

If there are multiple answers then print any of them.

Input

The only line contains two integers nn and mm (1n,m1051≤n,m≤105) — the number of vertices and the number of edges.

Output

If there exists no valid graph with the given number of vertices and edges then output "Impossible".

Otherwise print the answer in the following format:

The first line should contain the word "Possible".

The ii-th of the next mm lines should contain the ii-th edge (vi,ui)(vi,ui) of the resulting graph (1vi,uin,viui1≤vi,ui≤n,vi≠ui). For each pair (v,u)(v,u)there can be no more pairs (v,u)(v,u) or (u,v)(u,v). The vertices are numbered from 11 to nn.

If there are multiple answers then print any of them.

Examples
input
Copy
5 6
output
Copy
Possible
2 5
3 2
5 1
3 4
4 1
5 4
input
Copy
6 12
output
Copy
Impossible
Note

Here is the representation of the graph from the first example:

 

   这题无脑暴力 暴力真的出了奇迹 

   暴力枚举一遍就行了

 

    

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 1e5 + 10;
 4 const int INF = 0x3fffffff;
 5 typedef long long LL;
 6 using namespace std;
 7 int n, m;
 8 struct node {
 9     int x, y;
10     node () {}
11     node (int x, int y): x(x), y(y) {}
12 } qu[maxn];
13 int main() {
14     scanf("%d%d", &n, &m);
15     if (n - 1 > m) {
16         printf("Impossible\n");
17         return 0;
18     }
19     int k = 0, flag = 0;
20     for (int i = 1 ; i <= n ; i++) {
21         for (int j = i + 1 ; j <= n ; j++) {
22             if (__gcd(i, j) == 1) qu[k++] = node(i, j);
23             if (k == m) {
24                 flag = 1;
25                 break;
26             }
27         }
28         if (flag) break;
29     }
30     if (flag) {
31         printf("Possible\n");
32         for (int i = 0 ; i < k ; i++)
33             printf("%d %d\n", qu[i].x, qu[i].y);
34     } else  printf("Impossible\n");
35     return 0;
36 }

 

转载于:https://www.cnblogs.com/qldabiaoge/p/9314221.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/451977.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

解决 : org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 报错&#xff1a; org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.tanj.mapper.SendDeta…

网络爬虫--19.【Scrapy-Redis实战】分布式爬虫爬取房天下--环境准备

文章目录0. 思路一. 虚拟机Ubuntu0中安装Redis二. 虚拟机Ubuntu1中安装Redis三. Windows服务器上安装Redis四. 安装cmder五. 安装RedisDesktopManager六. 修改Windows中的配置文件redis.windows.conf七. Ubuntu连接Windows上 的Redis服务器-----------------------------------…

开发人员,请爱护你的身体

最近一周身体极度不适&#xff0c;口腔溃疡、嗓子痛、感冒咳嗽、发烧&#xff0c;统统来了一个遍&#xff0c;非常痛苦。所以最近一直关注有关于软件开发人员的身体健康问题的网站、文章。 看了许多文章&#xff0c;在结合自己在这一周之内痛苦的感受&#xff0c;所以才写这样…

tkinter中scale拖拉改变值控件(十一)

scale拖拉改变值控件 使用户通过拖拽改变值 简单的实现&#xff1a; 1 import tkinter2 3 wuya tkinter.Tk() 4 wuya.title("wuya") 5 wuya.geometry("300x2001020") 6 7 8 # 创建对象 9 scale1 tkinter.Scale(wuya, from_0, to100) 10 scale1.pac…

vue+elementUI开发实践问题总结

最近公司项目采用vue&#xff0c;实行前后端分离开发&#xff0c;采用element-ui框架&#xff0c;对于项目中遇到的问题进行记录&#xff0c;便于日后查询。 vueelementui怎样点击table中的单元格触发事件&#xff1f;官方文档是采用的cell-click方式。实际项目中需要在不同的t…

Socket的getInputStream()方法

Socket的getInputStream()方法可以获得网络连接输入&#xff0c;同时返回一个InputStream实例 。

计算机图形学理论(4):缓冲区

本系列根据国外一个图形小哥的讲解为本&#xff0c;整合互联网的一些资料&#xff0c;结合自己的一些理解。 什么是缓冲区&#xff1f; 缓冲区是保存某些数据的临时存储空间。 为什么我们需要缓冲区&#xff1f;原因很简单&#xff0c;当数据量很大时&#xff0c;因为计算机无…

解决:Every derived table must have its own alias

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 报错&#xff1a; com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Every derived table must have its own alias 解决&…

网络爬虫--20.【Scrapy-Redis实战】分布式爬虫获取房天下--代码实现

文章目录一. 案例介绍二.创建项目三. settings.py配置四. 详细代码五. 部署1. windows环境下生成requirements.txt文件2. xshell连接ubuntu服务器并安装依赖环境3. 修改部分代码4. 上传代码至服务器并运行一. 案例介绍 爬取房天下&#xff08;https://www1.fang.com/&#xff…

同一台电脑安装python2python3

【安装之前&#xff0c;先了解一下概念】 python是什么&#xff1f; Python是一种面向对象的解释型计算机程序设计语言&#xff0c;由荷兰人Guido van Rossum于1989年发明&#xff0c;第一个公开发行版发行于1991年。 Python是纯粹的自由软件&#xff0c; 源代码和解释器CPytho…

程序员的常见健康问题

其实这些问题不仅见于程序员&#xff0c;其他长期经常坐在电脑前的职场人士&#xff08;比如&#xff1a;网络编辑、站长等&#xff09;&#xff0c;都会有其中的某些健康问题。希望从事这些行业的朋友&#xff0c;对自己的健康问题&#xff0c;予以重视。以下是全文。 我最近…

Java中BufferedReader和InputStreamReader

BufferedReader 类BufferedReader 由Reader类扩展而来&#xff0c;提供通用的缓冲方式文本读取&#xff0c;而且提供了很实用的readLine&#xff0c;读取一个文本行&#xff0c;从字符输入流中读取文本&#xff0c;缓冲各个字符&#xff0c;从而提供字符、数组和行的高效读取。…

网络爬虫--21.Scrapy知识点总结

文章目录一. Scrapy简介二. Scrapy架构图三. Scrapy框架模块功能四. 安装和文档五. 创建项目六. 创建爬虫一. Scrapy简介 二. Scrapy架构图 三. Scrapy框架模块功能 四. 安装和文档 中文文档&#xff1a;https://scrapy-chs.readthedocs.io/zh_CN/latest/intro/tutorial.html …

Spring 定时任务的几种实现

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 近日项目开发中需要执行一些定时任务&#xff0c;比如需要在每天凌晨时候&#xff0c;分析一次前一天的日志信息&#xff0c;借此机会整…

trie树(字典树)

trie树学习 学习trie树 转载于:https://www.cnblogs.com/cjoierljl/p/9317023.html

Vue 教程第四篇—— Vue 实例化时基本属性

实例元素 el 实例元素指的是 Vue 实例化时编译的容器元素&#xff0c;或者说是 Vue 作用的元素容器 <div id"app"></div> var vm new Vue({el: #app}) 也可以为实例元素指定其它选择器 <div class"app"></div> var vm new Vue({…

Ubuntu将在明年推出平板及手机系统

4月26日下午消息&#xff0c;知名Linux厂商Canonical今天正式发布Ubuntu 12.04版开源操作系统。Ubuntu中国首席代表于立强透露&#xff0c;针对平板电脑的Ubuntu操作系统将在明年推出。 Ubuntu 12.04版开源操作系统发布 Ubuntu操作系统是一款开源操作系统&#xff0c;主要与OE…

scrapy框架异常--no more duplicates will be shown (see DUPEFILTER_DEBUG to show all duplicates)

解决方法&#xff1a; https://blog.csdn.net/qq_40176258/article/details/86527568 https://blog.csdn.net/weixin_39946931/article/details/88390797 谢谢博主分享&#xff01;

【BZOJ3590】[Snoi2013]Quare 状压DP

题解&#xff1a; 一道比较水的题 但这个测试数据极弱我也不知道我的代码正确性是不是有保证 构成一个边双联通 可以由两个有一个公共点的边双联通或者一个边双加一条链构成 所以我们需要要预处理出所有环 令f[i][j][k]表示起点为i&#xff0c;终点为j&#xff0c;经过点的状态…