题目链接:http://codeforces.com/problemset/problem/1009/D

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

题意大概就是,给出n,1到n的n个点,问你用m条边连接这n个点可不可行,若不可行,输出“impossible",若可行,输出“possible”,并且给出m条边分别连接的点,限制:每条边连接的两个点必须是互质的。

开始以为什么特殊的数学方法,后来发现直接枚举1到n里的i,j就可以过。

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
pair<int, int> ans[N];int gcd(int a,int b)    //判断是否互质
{if(a<b)return gcd(b,a);while(b){int t=b;b=a%b;a=t;}return a;
}int main()
{int n, m;scanf("%d%d", &n, &m);if (m < n - 1)     //连接n个点,最少n-1条边{puts("Impossible");return 0;}int cur = 0;for(int i=1;i<=n && cur<m;i++)for(int j=i+1;j<=n;j++){if(gcd(i,j)==1){ans[++cur]=make_pair(i,j);if(cur==m)break;}}if (cur != m)        //如果所有的互质数的对数不到m,连不成{puts("Impossible");return 0;}puts("Possible");for(int i=1;i<=m;i++)printf("%d %d\n", ans[i].first, ans[i].second);return 0;
}

codeforces-1009D Relatively Prime Graph相关推荐

  1. Codeforces 1009D:Relatively Prime Graph

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

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

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

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

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

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

  5. 【CodeForces - 124C】Prime Permutation(数学,思维,小结论)

    题干: You are given a string s, consisting of small Latin letters. Let's denote the length of the stri ...

  6. 【CodeForces - 271B 】Prime Matrix (素数,预处理打表,思维)

    题干: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single ...

  7. 【CodeForces - 246D】Colorful Graph (暴力,图,存边,STL)

    题干: You've got an undirected graph, consisting of n vertices and m edges. We will consider the graph ...

  8. Codeforces 716D - Complete The Graph(最短路)

    题意:给定n个点,m条边,以及起点s,终点t,问你图中是否存在s->t的最短路为L,其中权值为0的可以任意修改. 思路:对给定的边分为2类,权重不为0的直接扔进去建图,权重为0的边先存起来.接着 ...

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

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

  10. 搜索 —— 暴力搜索

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

最新文章

  1. java字符串的知识总结
  2. 从源码角度来读Handler
  3. PATH环境变量设置
  4. idea GsonFormat插件使用报错 StringIndexOutOfBoundsException: begin 0, end -1, length 9
  5. JavaScript实现trial Division试除法算法(附完整源码)
  6. mysql删除表中数据报错:[Err] 1206 - The total number of locks exceeds the lock table size
  7. [AGC026D]Histogram Coloring
  8. 程序10 VC编写批量重命名工具
  9. Magento: 后台添加预览按钮 View product in frontend from Magento admin
  10. 第二部分:开发简要指南-第六章 使用Fragments构建动态UI
  11. springboot日志配输出路径配置_Spring Boot 日志配置方法(超详细)
  12. 1008 数组元素循环右移问题(C语言)
  13. 解决go get下载包失败问题
  14. iphone app开发实战很重要:《iPhone App开发实战手册》读后感
  15. Android 中自定义组件例子一(中级)
  16. Python 复数类型(详解)
  17. 宝塔linux 加载zend,Linux CentOS 安装 Zend Guard Loader 组件
  18. 数学笔记:集合及其运算
  19. 爬取图片,并按比例划分数据集
  20. WIFI AP和STATION

热门文章

  1. xp系统开启wlan服务器,XP系统笔记本怎么设置无线网络?
  2. c语言知识点总结300字,大二学年自我总结300字 .doc
  3. 康托尔三分集是不可列集的证明
  4. N1完美刷入Armbian系统
  5. Go 通道 Chan 详解
  6. 服装制造业信息化系统分析(一)
  7. 谈谈Android中的persistent属性
  8. 北京375路公交车灵异事件真相
  9. 2020科目一考试口诀_2020年驾考科目一考试技巧与口诀
  10. 人工智能应用计算机的实例,人工智能应用实例介绍