Educational Codeforces Round 47 (Rated for Div. 2) D. Relatively Prime Graph(暴力)

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个顶点m条边的连通图,并且连通图相邻顶点互质。

思路:由连通图可知n个顶点最少有m-1(两个顶点一条边)条边,然后暴力即可。

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for(int i = (s); i < (e); i++)
#define FOE(i,s,e) for(int i = (s); i <= (e); i++)
#define FOD(i,s,e) for(int i = (s); i >= (e); i--)
#define ll long long
#define lb long double
#define pb push_back
#define mp make_pair
#define pff pair<double, double>
struct node
{
    int x, y;
}edge[100005];
int main()
{
    int n, m, t = 0, flag = 0;
    cin >> n >> m;
    if(n - 1 > m) { puts("Impossible"); ; return 0; }
    FOE(i,1,n)
    {
        FOE(j,i+1,n)
        {
            if(__gcd(i,j) == 1)
            {
                edge[t].x = i;
                edge[t++].y = j;
                if(t == m)
                {
                    flag = 1;
                    break;
                }

            }
        }
        if(flag == 1) break;
    }
    if(flag)
    {
        puts("Possible");
        FOR(i,0,m) cout <<edge[i].x<<" "<<edge[i].y<<endl;
    }
    else puts("Impossible");
}

猜你喜欢

转载自blog.csdn.net/sugarbliss/article/details/81068223