Let’s call an undirected graph G=(V,E)relatively prime if and only if for each edge (v,u)∈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 11 to |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 (1≤n,m≤10-5) — 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) of the resulting graph (1≤vi,ui≤n,vi≠ui). For each pair (v,u) there can be no more pairs (v,u)or (u,v). The vertices are numbered from 11 to n.

If there are multiple answers then print any of them.

Examples
Input
5 6
Output
Possible
2 5
3 2
5 1
3 4
4 1
5 4
Input
6 12
Output
Impossible
Note
Here is the representation of the graph from the first example:

  • 注意,因为m最大为1e5,因此直接暴力
#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define _ ios::sync_with_stdio(false)
#define mk make_pair
bool SUBMIT = 1;
typedef long long ll;
using namespace std;
const double PI = acos(-1);
const int inf = 1e5+50;
int n,m,k=0;
struct node{int u,v;node(int u,int v):u(u),v(v){}
};
vector<node>ans;
int main()
{//if(!SUBMIT)freopen("i.txt","r",stdin);else _;cin>>n>>m;for(int i=1;i<n&&k<m;i++)for(int j=i+1;j<=n&&k<m;j++)if(__gcd(i,j)==1){ans.pb(node(i,j));k++;}if(m<n-1||k<m){printf("Impossible\n");return 0;}printf("Possible\n");for(int i=0;i<ans.size();i++){cout<<ans[i].u<<" "<<ans[i].v<<endl;}return 0;
}

B - Relatively Prime Graph -CodeForces - 1009D-csdn博客相关推荐

  1. taoqick 搜索自己CSDN博客

    L1 L2正则化和优化器的weight_decay参数 kaiming初始化的推导 Pytorch动态计算图 Pytorch自动微分机制 PyTorch中在反向传播前为什么要手动将梯度清零? 通俗讲解 ...

  2. CSDN博客写作编辑器如何使用?

    文章目录 0.引言 1.快捷键 2.文字 3.链接和代码 4.注脚和注释 5.公式 6.表 7.图 0.引言   笔者阅读CSDN博客已有五年,从最初的学习跟随者,到现在的CSDN博客创造者,这其中的 ...

  3. 关于博客园与CSDN博客同步的说明

    把博客园与CSDN比较,我认为博客园有技术内容优势,CSDN有行业资源优势,两者都比较重要.因此在两家网站同步发布博客. CSDN博客地址:http://blog.csdn.net/caoshiyin ...

  4. 2019年度CSDN博客之星TOP10榜单揭晓,你上榜了吗?

    培根说,『读书造成充实的人,会议造成未能觉悟的人,写作造成正确的人』. 在短信短视频快速迭代的快时代,更深度的思考.更正确的实践,更成体系的写作与分享,尤显可贵.这里,每一篇博文都是开发者实战的经验解 ...

  5. CSDN博客的创建及使用

    文章目录 一.创建CSDN博客详细流程 1. 注册 2. 绑定手机 二.编辑和发布博客 1. 设置markdown格式 2. 发布文章 3. 常见的markdown语法 3.1 分级标题 3.2 目录 ...

  6. 这是一名南京985AI硕士,CSDN博客专家

    微信公众号推荐 AI蜗牛车公众号 微信公众号<AI蜗牛车>,公众号致力于技术项目化,具体化,思考化,会写系列的项目工程文章,细致到位,也会写一个读物的读书笔记,或者一个语言/框架的学习笔记 ...

  7. CSDN博客获取积分规则!不是下载积分!如何快速增长积分!

    博客积分是CSDN对用户努力的认可和奖励,也是衡量博客水平的重要标准. 博客等级也将由博客积分唯一决定.积分规则具体如下: 1.每发布一篇原创或者翻译文章:可获得10分: 2.每发布一篇转载文章:可获 ...

  8. 类选择器和所作用的标签一起写为什么不起作用? - CSDN博客

    原文:类选择器和所作用的标签一起写为什么不起作用? - CSDN博客 HTML代码: css样式: 这不是将样式作用于circle类下的有current类的li标签吗?为什么不起作用? 原因: 选择器 ...

  9. microsoft edge 打不开 csdn 博客

    microsoft edge 打不开 csdn 博客

  10. 如何转载别人的csdn博客

    起意 看到一篇不错的博客,想转载但是不会(没有转载键),网搜发现没有Chrome浏览器的详细转载办法,受博主Bily猪启发,弄了这个教程,给小白的,大神勿嗤.时间紧急的直接看总结. 实践 检查.在喜欢 ...

最新文章

  1. 单片机有什么好的网课?
  2. python学习笔记四一列表元组字典等
  3. JAVA设计模式总结之23种设计模式
  4. 坚决不要使用SQL逻辑删除本番环境的数据,降低程序风险
  5. 德裔美国Delphi程序员霍尔格-弗里克博士访谈
  6. Python 定时关机、重启命令
  7. stm32c语言写数码管定时器,【程序】STM32F103单片机使用定时器DMA进行全自动8位数码管动态扫描...
  8. 基于单片机at89s52的频率计设计c语言程序,基于AT89S52单片机电子万年历设计(附程序,电路原理图)...
  9. linux中mysql启动时遇到MySql server PID file cound not be found
  10. [苹果开发者账号]02 申请苹果开发者账号 快速申请邓白氏编码DUNS(提示:抱歉,您暂时不能注册)
  11. 三、道阻且长之单例模式
  12. Centos7登陆颜色修改#PS1
  13. echarts柱状图实现正负值不同颜色在上方显示数值
  14. 将项目提交到码云时,异常: remote: [31mIncorrect username or password ( access token )[0m
  15. /usr/include/linux/if_ppp.h:117: error: expected specifier-qualifier-list before 'aligned_u64' 解决方式
  16. Unity游戏存档的四种方式
  17. CUMT学习日记——软件工程考前速成记录
  18. 黑莓手机支持的媒体播放类型
  19. Java基础入门(十八)之NIO
  20. 世界核电迎“中国芯” 自主研发建设全球首座高温气冷堆

热门文章

  1. DASCTF X GFCTF 2022十月挑战赛 WriteUp
  2. 个人网站有赞云支付接口申请方法
  3. 4位加法器四级流水线、4位加法器两级流水线以及32位加法器八级流水线设计
  4. 《游戏制作人手册》读书笔记
  5. 作业(数组)---运行环境winTC(一)
  6. 【python教程入门学习】Python字典及基本操作(超级详细)
  7. 敏捷经验教训, 开发总结!
  8. 免费的国内代理服务器、国内代理IP地址
  9. JavaSE实战项目:飞翔的小鸟(完整版)
  10. 【吴恩达】机器学习第16章异常检测以及ex8部分编程练习