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. codeforces 355A Vasya and Digital Root

    题意就是找出一个长度为k的整数,使得它的root为d,k的可能取值为1-1000. 第一眼看到这个题,无从下手,想到那么长的数,暴力肯定超时.其实不然,题目要求只要输出任何一个满足条件的即可,因为任何 ...

  2. MRCPv2在电信智能语音识别业务中的应用

    1. MRCPv2协议简介 媒体资源控制协议(Media Resource Control Protocol, MRCP)是一种基于TCP/IP的通讯协议,用于客户端向媒体资源服务器请求提供各种媒体资 ...

  3. 基于Spring注解的上下文初始化过程源码解析(二)

    上一篇看完了register方法的代码,继续跟后面代码 后面执行refresh方法,代码清单如下: public void refresh() throws BeansException, Illeg ...

  4. mac安装ElasticSearch+head+node+一个例子~

    1.下载ElasticSearch 官网下载链接:https://www.elastic.co/cn/downloads/past-releases(进去的可能会比较慢,网络好的情况下会好一些) 我下 ...

  5. hadoop学习(七)----mapReduce原理以及操作过程

    前面我们使用HDFS进行了相关的操作,也了解了HDFS的原理和机制,有了分布式文件系统我们如何去处理文件呢,这就的提到hadoop的第二个组成部分-MapReduce. MapReduce充分借鉴了分 ...

  6. springmvc异步处理

    好久没有写过博客了,都是看大牛的文章,略过~~ 突然感觉成长在于总结!废话不多说,开干 由于是公司项目,所以不方便给出代码,看图操作 在项目util目录下创建工具类TaskExecutorConfig ...

  7. HTML加载FLASH(*.swf文件)详解

    引言 在web项目中经常会遇到在线浏览word文档,通常解决方法将word转换成pdf,然后在线浏览,但是在实际实现过程中,由于阅读器的原因,用户可以直接下载该pdf,这显然不是我们想要的,通过网络搜 ...

  8. GoAccess 分析 Nginx 日志

    0x00 事件 帮助朋友搭建了博客,运行过了一段时间,准备发个网站分析报告给他. 有效的数据只有 Nginx 的访问日志,于是使用决定 GoAccess 工具对这个日志进行分析, 0x01 安装 吾使 ...

  9. Windows Server 2008配置系统安全策略

    下面学习Windows Server 2008配置系统安全策略 在工作组中的计算机本地安全策略有 用户策略,密码策略,密码过期默认42天 服务账户设置成永不过期,帐户锁定策略,本地策略,审核策略,计算 ...

  10. Django-channels 实现WebSocket实例

    引入 先安装三个模块 pip install channels pip install channels_redis pip install pywin32 创建一个Django项目和一个app 项目 ...