D. Relatively Prime Graph

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 (1≤n,m≤1051≤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 (1≤vi,ui≤n,vi≠ui1≤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:

题意:给出n,m表示有n个点编号(1-n),你要构造一个m条边的的图形,使得相连的两个点互为素数,如果可以构造出,输出 Possible 并且输出所有边的关系,否则输出   Impossible

思路:首先,如果m<n-1的话,直接可以排除了,因为n个点最小要用n-1条边,然后,我们可以只要暴力不断以节点和与之互素的节点建边即可(gcd的复杂度非常小,所以可以直接用gcd来判断,据说,gcd递归的次数不会超过较小的那个数的5倍)

#include "iostream"
#include "vector"
using namespace std;
const int Max=1e5+10;
vector<int> G[Max];
int X[Max],Y[Max];
int gcd(int a,int b)
{return b?gcd(b,a%b):a;
}
int main()
{int n,m,ans=0,tot=0;cin>>n>>m;if(m<n-1){cout<<"Impossible"<<endl; return 0;}int x=3,t=2;  m-=n-1;//1和所有其他点gcd=1所以先减去n-1,从2开始枚举while(m&&t<n){while(gcd(t,x)!=1) x++;if(x>n) {t++;x=t+1;continue;}X[tot]=t,Y[tot++]=x;x++,m--;}if(m>0) cout<<"Impossible"<<endl;//枚举完所有点,边还没用完,那么一定不可以else{cout<<"Possible"<<endl;for(int i=1;i<n;i++) cout<<"1 "<<i+1<<endl;for(int i=0;i<tot;i++)cout<<X[i]<<" "<<Y[i]<<endl;}return 0;
}

D. Relatively Prime Graph codeforces 1009 D相关推荐

  1. Codeforces Global Round 4-D. Prime Graph(伯特兰-切比雪夫定理)

    题目:Codeforces Global Round 4-D. Prime Graph 题意:给出n(顶点的个数),要求所得图满足: 1.无平行边和自环 2.边的总数是个质数 3.每个点的度(也就是点 ...

  2. Codeforces 1009D:Relatively Prime Graph

    D. Relatively Prime Graph time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  3. Relatively Prime Powers CodeForces - 1036F (莫比乌斯函数容斥)

    Relatively Prime Powers CodeForces - 1036F Consider some positive integer xx. Its prime factorizatio ...

  4. 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( ...

  5. Codeforces Global Round 4 - 1178D. Prime Graph(构造+切比雪夫定理)

    题目链接:https://codeforces.com/contest/1178/problem/D 题意:给出  个点,要求构成一个简单图,使得边的总数是素数,并且每个点的度数也是素数. 思路:如果 ...

  6. Harmonious Graph CodeForces - 1253D(思维+并查集)

    You're given an undirected graph with n nodes and m edges. Nodes are numbered from 1 to n. The graph ...

  7. Educational Codeforces Round 47 (Div 2) (A~G)

    目录 Codeforces 1009 A.Game Shopping B.Minimum Ternary String C.Annoying Present D.Relatively Prime Gr ...

  8. js获取服务器响应头信息,js获取HTTP的请求头信息

    [IIS]IIS扫盲(二) iis - IIS之Web服务器建立 第一篇 IIS之Web服务器  一.建立第一个Web站点  比如本机的IP地址为192.168.0.1,自己的网页放在D:\Wy目录下 ...

  9. 搜索 —— 暴力搜索

    [暴力搜索] 暴力搜索,就是将所有情况都举出,并判断其是否符合题目条件.其基本方法是分析题意后,找到一个合适的维度列举每一个元素,以完成题目. 一般主流的 OJ 中,1000ms 的时间限制下可以运行 ...

  10. 最小生成树的java实现

    文章目录 一.概念 二.算法 2.1 Prim算法 2.2 Kruskal算法 笔记来源:中国大学MOOC王道考研 一.概念 连通图:图中任意两点都是连通的,那么图被称作连通图 生成树:连通图包含全部 ...

最新文章

  1. 微信小程序填坑之路(三):布局适配方案(rpx、px、vw、vh)
  2. Pythonic版冒泡排序和快速排序(附:直接插入排序)
  3. 中兴智能视觉大数据报道:人脸识别准确率高达99.8%
  4. springboot profiles
  5. linux终端配备时钟oh-my-zsh主题
  6. 《犯罪心理学》读书笔记(part11)--犯罪心理的性别差异(中)
  7. 什么是 SAP UI5 的 Element binding
  8. 前端微信签名验证工具_微信小程序API 用户数据的签名验证和加解密
  9. LeetCode刷题——344. 反转字符串
  10. 斜杠的意思是或还是和_pua是什么意思?我pua pua的解释给我老婆听!
  11. oracle 获得表字段名,注释等的sql语句 .
  12. 计算机我的云盘在哪里看,怎么设置在我的电脑中显示百度网盘
  13. win10如何局部截图
  14. 触发器详解——(三)T触发器
  15. 【2021年度总结】积跬步,「卷」千里,2022 继续「卷」
  16. SpringBoot + FreeMarker + FlyingSaucer 实现PDF在线预览、打印、下载
  17. 【论文解读 WWW 2019 | HAN】Heterogeneous Graph Attention Network
  18. Remix IDE的安装和使用
  19. 玩一回没有“蒋氏”的溪口
  20. Grafana变量介绍

热门文章

  1. Acwing1183. 电力
  2. 数列极限导出重要无理数
  3. MySQL said: Authentication plugin ‘caching_sha2_password‘ cannot be loaded... 阿星小栈
  4. 校园火灾Focue-3---》音乐
  5. 身份证上传尺寸太大如何缩小?改照片尺寸的简单方法
  6. 一个未完毕创业项目的思考——创业杂记
  7. 东北大学 计算机网络,东北大学计算机网络B卷(附答案).pdf
  8. Android打开项目一直build的问题解决
  9. Pandas数据分析
  10. 【吴恩达】机器学习第16章异常检测以及ex8部分编程练习