Codeforces 1009D 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≤10^5 ) — 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條邊,使得相連的兩個節點編號gcd值爲1,且n個節點連通,求是否能構造出來m條邊。

解題思路:gcd==1我們就知道兩個數互質,這樣的話 我們就可以想到用歐拉函數來知道幾條邊。

如果m<n-1的話 這顯然是不可能的。

歐拉函數的定義:

    在數論中,對於正整數N,少於或等於N ([1,N]),且與N互質的正整數(包括1)的個數,記作φ(n)。

     φ函數的值:

    φ(x)=x(1-1/p(1))(1-1/p(2))(1-1/p(3))(1-1/p(4))…..(1-1/p(n)) 其中p(1),p(2)…p(n)爲x

的所有質因數;x是正整數; φ(1)=1(唯一和1互質的數,且小於等於1)。注意:每種質因數只有一個。

     例如:

         φ(10)=10×(1-1/2)×(1-1/5)=4;

         1 3 7 9

         φ(30)=30×(1-1/2)×(1-1/3)×(1-1/5)=8;

         φ(49)=49×(1-1/7)=42;

根據歐拉函數 我們可以知道573以內的互素的對數就已經超過1e5了.

所以我們直接暴力尋找邊的數量就行。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=1e5+10;
int n,m;
vector<pair<int, int > > ans;
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
int main(){
	int i,j;
	while(scanf("%d%d",&n,&m)!=EOF){
		if(m<n-1){
			printf("Impossible\n");
			continue;
		}
		ans.clear();
		for(i=1;i<=n&&ans.size()<=m;i++){
			for(j=i+1;j<=n&&ans.size()<=m;j++){
				if(gcd(i,j)==1){
					ans.push_back(make_pair(i,j));
				}
			}
		}
		if(m>ans.size()){
			printf("Impossible\n");
			continue;
		}
		printf("Possible\n");
		int tot=ans.size();
		for(i=0;i<m;i++){
			printf("%d %d\n",ans[i].first,ans[i].second);
		}
	}
	return 0;
} 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章