Relatively Prime Graph

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 1 to |V|

.

Construct a relatively prime graph with n
vertices and m

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 n
and m (1≤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 i-th of the next m lines should contain the i-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 1 to n.If there are multiple answers then print any of them.

Examples
Input

5 6OutputPossible
2 5
3 2
5 1
3 4
4 1
5 4Input6 12OutputImpossible

Note

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

题意:给定n个点(1-n),让你构成一个图有m条边,使得每个边到两端点编号是互质的。
分析:一开始想如果暴力到话是O(n2n2n^2log(n)),即枚举每个点,然后两辆求gcd,n是1e51e51e^5会超时,就没写,以为有别的什么巧妙方法。实在没想出来搜了题解发现emmmmm….
数据里限定了m也是1e51e51e^5级别的数,所以虽然是二重循环但是最多循环m次就停止了。
如果impossible【及贪心完造的边还没有m这么多】,那n一定很小,小到n2 log(n)n2log(n)n^2\ log(n)可以过;
如果possible,那一定n2n2n^2还没有枚举完就造完m条边,直接break了。【因为n2n2n^2枚举完造的边与m不是一个数量级的数】

code:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int u[maxn],v[maxn],edge;
int gcd(int a,int b){if(b == 0) return a;else return gcd(b,a%b);
}
int main(){int n,m;edge = 0;scanf("%d%d",&n,&m);if(m < n-1){printf("Impossible\n");return 0;}for(int i = 1; i <= n; i++){for(int j = i+1; j <= n; j++){if(edge == m) break;if(gcd(i,j) == 1){u[++edge] = i;v[edge] = j;}}if(edge == m) break;}if(edge == m){printf("Possible\n");for(int i = 1; i <= edge; i++){printf("%d %d\n",u[i],v[i]);}}elseprintf("Impossible\n");return 0;
}

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

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

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

  4. 图论 ---- C. Graph Transpositions(数据分阶段分层图最短路(二维) + 贪心)

    题目链接 题目大意: 对于给你一个有向图,你有两次操作 你单前在uuu点从u→vu\rightarrow vu→v花费1s1s1s 你可以把整个图的边都反向!!就是u→vu\rightarrow vu ...

  5. UVALive 4225 Prime Bases 贪心

    Prime Bases 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&a ...

  6. ARC080F - Prime Flip(贪心,差分,二分图匹配)

    ARC080F - Prime Flip Solution 差分,转化为每次可以翻转i,j(j−i∈oddprime)i,j(j-i\in odd\;prime)i,j(j−i∈oddprime). ...

  7. 【贪心】数据备份(P6320)

    正题 P6320 题目大意 有n个点,相邻的点不能同时选,问你选k个的最小代价 解题思路 考虑贪心取每个点,取了一个点后设置一个撤回点,就是把该点的选择取反,同时选择左右,这样直接用堆维护即可 cod ...

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

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

  9. 数据治理展示血缘关系的工具_Nebula Graph 在微众银行数据治理业务的实践

    本文为微众银行大数据平台:周可在 nMeetup 深圳场的演讲这里文字稿,演讲视频参见:B站 自我介绍下,我是微众银行大数据平台的工程师:周可,今天给大家分享一下 Nebula Graph 在微众银行 ...

  10. 从 Neo4j 导入 Nebula Graph 实践见 SPark 数据导入原理

    本文主要讲述如何使用数据导入工具 Nebula Graph Exchange 将数据从 Neo4j 导入到 Nebula Graph Database.在讲述如何实操数据导入之前,我们先来了解下 Ne ...

最新文章

  1. Globalization Resources
  2. 解决“错误 D8016 “/ZI”和“/Gy-”命令行选项不兼容 ”问题
  3. mysql int zerofill_Mysql 中int[M]—zerofill-阿里云开发者社区
  4. loadrunner简单的例子(demo)
  5. WCF分布式开发步步为赢(0):WCF学习经验分享,如何更好地学习WCF?
  6. 我们讨论的是《战争之城》的一个简单版本。如果地图上只有空旷的空间,河流,钢墙和砖墙。你的任务是尽快得到奖金,假设没有敌人会打扰你(见下图) 你的坦克不能穿过河流和墙壁,但它可以通过射击摧毁砖墙。当你击
  7. centos7调节虚拟机字体_初次安装虚拟机中Ubuntu16.04系统设置的一些小问题(小白教程)...
  8. 【UI/UX】GUI设计指南
  9. SLB+Tomcat时request.RemoteAddr无法获取正确的客户端IP的问题解决方案
  10. 坑爹系列:sizeof运算符
  11. 根据出库、入库表,实现对库存的信息查询
  12. 超高频RFID通道门禁 仓储物流收发货系统应用
  13. 『paddle』paddleclas 学习笔记:图像识别
  14. ET5.0 简单了解
  15. ios无痕埋点_无痕埋点方案探究
  16. 联想怎么启动windows无线服务器,Windows7系统下开启无线的多种方法
  17. kali 安装netspeed 网络流量监视器
  18. Google代码规范书写格式,告别丑陋代码
  19. python导入siri_python利用不到一百行代码实现一个小siri
  20. java 通过SSL/TLS加密https建立连接

热门文章

  1. 拿中国互联网的两个航母说事(一)--腾讯战略
  2. ZYNQ的Linux Linaro系统镜像制作SD卡启动
  3. python库文件简介整理
  4. python不能使用下标运算的是()_下列选项中,不能使用下标运算的是( ).
  5. python中%s是什么意思_python的%s是什么意思
  6. [转载]全国高校IPv6地址分配情况
  7. 看球二三事 - 世界杯征文
  8. qq音乐网络异常获取音乐失败_QQ音乐无法播放_为什么qq音乐总是提示歌曲无效或网络连接失败?...
  9. 【元宇宙系列】元宇宙的创世居民——M 世代(Mateverse)
  10. java飞翔的小鸟游戏实验报告,BirdGame 飞翔的小鸟游戏源码,仿照 编写的java版本 ,所有的 功能完整。 s 249万源代码下载- www.pudn.com...