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个点,编号为1~n。有m条边,要求每条边的顶点的最大公约数为1(并且没有平行边和环),如果这些点和边能组成无向的连通图,并且边和顶点都没有剩余,则输出Possible,并输出可能的边(用顶点表示),否则输出Impossible

AC代码:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define ll long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
const double E=exp(1);
const int maxn=1e6+10;
using namespace std;
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);
}
ll vis[maxn][2];
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
ll n,m;
cin>>n>>m;
ms(vis);
if(m<n-1)//只有两个点,一条边
cout<<"Impossible"<<endl;
else
{
ll k=0;
for(ll i=1;i<n;i++)
for(ll j=i+1;j<=n;j++)
{
if(gcd(i,j)==1)//i和j的最大公约数为1,说明两点可以相连
{
vis[k][0]=i;
vis[k][1]=j;
k++;//i,j看做边的两点,并更新k的值
if(k>m)
break;//这个停止不能少!!!要不然数太多,数组存不下!!
}
}
if(k<m)
cout<<"Impossible"<<endl;
else
{
cout<<"Possible"<<endl;
for(int i=0;i<m;i++)
{
cout<<vis[i][0]<<" "<<vis[i][1]<<endl;
}
}
}
return 0;
}

Codeforces 1009D:Relatively Prime Graph的更多相关文章

  1. 【Codeforces 1009D】Relatively Prime Graph

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 1000以内就有非常多组互质的数了(超过1e5) 所以,直接暴力就行...很快就找完了 (另外一开始头n-1条边找1和2,3...n就好 [代 ...

  2. Codeforces Global Round 4 Prime Graph CodeForces - 1178D (构造,结论)

    Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wan ...

  3. codeforces 715B:Complete The Graph

    Description ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m ...

  4. Codeforces 385C Bear and Prime Numbers

    题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...

  5. 译:Local Spectral Graph Convolution for Point Set Feature Learning-用于点集特征学习的局部谱图卷积

    标题:Local Spectral Graph Convolution for Point Set Feature Learning 作者:Chu Wang, Babak Samari, Kaleem ...

  6. Codeforces 385C Bear and Prime Numbers(素数预处理)

    Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...

  7. 算法:图(Graph)的遍历、最小生成树和拓扑排序

    背景 不同的数据结构有不同的用途,像:数组.链表.队列.栈多数是用来做为基本的工具使用,二叉树多用来作为已排序元素列表的存储,B 树用在存储中,本文介绍的 Graph 多数是为了解决现实问题(说到底, ...

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

  9. Relatively Prime Graph CF1009D 暴力 思维

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

随机推荐

  1. python16_day37【爬虫2】

    一.异步非阻塞 1.自定义异步非阻塞 import socket import select class Request(object): def __init__(self,sock,func,ur ...

  2. SpringData修改和删除操作

    SpringData的查询我们已经学完了,我们现在就研究一下SpringData的修改和删除. @Modifying 注解和事务 @Query 与 @Modifying 这两个 annotation一 ...

  3. VS2010/MFC编程入门之十五(对话框:一般属性页对话框的创建及显示)

    属性页对话框包括向导对话框和一般属性页对话框两类,上一节鸡啄米讲了如何创建并显示向导对话框,本节将继续介绍一般属性页对话框的创建和显示. 实际上,一般属性页对话框的创建和显示过程和向导对话框是很类似的 ...

  4. ACM-ICPC 2017 Asia Shenyang Solution

    A: BBP Formula https://www.cnblogs.com/LzyRapx/p/7802790.html #include <bits/stdc++.h> using n ...

  5. 使用 shell 脚本对 Linux 系统和进程资源进行监控

    Shell 简介 Shell 语言对于接触 LINUX 的人来说都比较熟悉,它是系统的用户界面,提供了用户与内核进行交互操作的一种接口.它接收用户输入的命令并把它送入内核去执行.实际上 Shell 是 ...

  6. 尚未指定报表“Report1”的报表定义

    在做RDLC项目中遇到这样的错误 本地报表处理期间出错. 尚未指定报表“Report1”的报表定义 未将对象引用设置到对象的实例. 解决方案: 打开reportViewer->LocalRepo ...

  7. 梅尔频率倒谱系数(MFCC) 学习笔记

    最近学习音乐自动标注的过程中,看到了有关使用MFCC提取音频特征的内容,特地在网上找到资料,学习了一下相关内容.此笔记大部分内容摘自博文 http://blog.csdn.net/zouxy09/ar ...

  8. python遗留问题

    def assert_element_in_page_source(s): print type(s) print s #assert s in driver.page_sourcecommand=' ...

  9. eclipse中gradle插件安装

    help===>install software===>http://download.eclipse.org/buildship/updates/e46/releases/2.x/

  10. INNODB存储引擎表空间

    这片文章主要是对innodb表空间的一些说明: innodb中表空间可以分为以下几种: 系统表空间 独立表空间 undo表空间 临时表空间(temporary tablespace) 通用表空间(ge ...