Relatively Prime Graph (暴力+GCD)

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 6

Output

Possible
2 5
3 2
5 1
3 4
4 1
5 4

Input

6 12

Output

Impossible

Note

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

题意:能否构建一个含有n个点,m条边的无向图满足以下条件

        1.无自环,无重边

        2.一条边的两个端点互质(gcd(u,v)=1)

        3.无悬浮点,每点必须与一条边相连

思路:直接暴力求解

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
typedef pair<int,int> ple;
const int N = 1e5+5;
set<ple>se;
set<ple>::iterator it;
int gcd(int x,int y){
	while(y){
		int z=x%y;
		x=y;
		y=z;
	}
	return x;
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int ans=0;
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			if(gcd(i,j)==1){
				ans++;
				se.insert(make_pair(i,j));
			}
			if(ans==m) break;
		}
		if(ans==m) break;
	}
	if(ans<m||m<n-1) printf("Impossible\n");
	else{
		printf("Possible\n");
		for(it=se.begin();it!=se.end();it++)
		   printf("%d %d\n",it->first,it->second);
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值