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:

emmm,没想到直接暴力过了。。

直接暴力最大公约数为1的对数,当对数超过m直接break,没有时间超限

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
typedef long long ll;
vector< pair<ll,ll> > edge;
ll gcd( ll a, ll b ) {
if( a == 0 ) {
return b;
} else if( b == 0 ) {
return a;
}
return gcd( b, a%b );
}
int main() {
ll n, m;
cin >> n >> m;
if( m < n-1 ) {
cout << "Impossible" << endl;
} else {
for( ll i = 1; i < n; i ++ ) {
for( ll j = i+1; j <= n; j ++ ) {
if( gcd(i,j) == 1) {
edge.push_back(make_pair(i,j));
if( edge.size() > m ) {
break;
}
}
}
}
if( edge.size() < m ) {
cout << "Impossible" << endl;
} else {
cout << "Possible" << endl;
for( ll i = 0; i < m; i ++ ) {
cout << edge[i].first << " " << edge[i].second << endl;
}
}
}
return 0;
}

  

Relatively Prime Graph CF1009D 暴力 思维的更多相关文章

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

  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. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

  4. 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)

    湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...

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

  6. Educational Codeforces Round 47 (Rated for Div. 2) :D. Relatively Prime Graph

    题目链接:http://codeforces.com/contest/1009/problem/D 解题心得: 题意就是给你n个点编号1-n,要你建立m条无向边在两个互质的点之间,最后所有点形成一个连 ...

  7. Codeforces Round #286 (Div. 2)B. Mr. Kitayuta's Colorful Graph(dfs,暴力)

    数据规模小,所以就暴力枚举每一种颜色的边就行了. #include<iostream> #include<cstdio> #include<cstdlib> #in ...

  8. UVA 10200 Prime Time【暴力,精度】

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  9. 暴力/思维 HDOJ 5386 Cover

    题目传送门 /* 题意:给出刷墙的所有的方法,求一种顺序,使得原矩阵刷成目标矩阵 暴力:(题解)我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可 */ /* ...

随机推荐

  1. 两份简单的logstash配置

    input{http{port=>7474}} filter{ grok{ match =>{ #"message" => "%{COMBINEDAPA ...

  2. Kafka学习(四)-------- Kafka核心之Producer

    通过https://www.cnblogs.com/tree1123/p/11243668.html 已经对consumer有了一定的了解.producer比consumer要简单一些. 一.旧版本p ...

  3. Java Grammer:数据类型

    Java的数据类型 我们知道,Java是一种强类型语言,类型对于Java语言来说非常的重要不言而喻,在Java中,分为基础数据类型和引用数据类型,其中基础数据类型分为了四类八种: 下面,我们来分别说一 ...

  4. oracle 正确删除归档日志,并清除 V$ARCHIVED_LOG 数据

    1. 连接 RMAN 管理 rman target / 2. 查看归档日志列表 RMAN> crosscheck archivelog all; 3. 删除所有归档日志 RMAN> DEL ...

  5. 同时运行多个 tomcat 修改端口

    修改 tomcat 配置文件,路径: tomcat_home/conf/server.xml  1.HTTP端口,默认8080,如下改为8081 <Connector connectionTim ...

  6. Python 四大主流 Web 编程框架

    Python 四大主流 Web 编程框架 目前Python的网络编程框架已经多达几十个,逐个学习它们显然不现实.但这些框架在系统架构和运行环境中有很多共通之处,本文带领读者学习基于Python网络框架 ...

  7. 低版本IE兼容 H5+CSS3 方案

    [主要是针对ie6 7 8对支持和让老浏览器支持html5+css3的一些js脚本] html5shiv.js  // 让IE8及耕地版本的IE识别section,article,nav等html5元 ...

  8. p2p 打洞专场(转)

    就像1000个人眼中有1000个哈姆雷特一样,每个人眼中的区块链也是不一样的!作为技术人员眼中的区块链就是将各种技术的融合,包括密码学,p2p网络,分布式共识机制以及博弈论等.我们今天就来讨论一下区块 ...

  9. cs231n---循环神经网络

    1 RNN介绍 (1)一对多,多对一,多对多的任务 传统的神经网络只能处理一对一的任务,而RNN可以处理一对多,多对一,多对多的任务: 其中,一些典型的应用如下: Image Captioning:i ...

  10. tk.mybatis扩展通用接口

    一.tk.mybatis已经为我们封装好了许多拆箱即用的通用mapper,但在实际的项目开发中想必不少小伙伴在数据库设计中都会采用逻辑删除这种方案,再去使用通用的mapper接口就不行了.这时候就需要 ...