题面在这里!

直接暴力找点对就行了,可以证明gcd=1是比较密集的,所以复杂度略大于 O(N log N)

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5; int gcd(int x,int y){ return y?gcd(y,x%y):x;} int n,m,u[N+5],v[N+5]; int main(){
scanf("%d%d",&n,&m);
if(n-1>m){ puts("Impossible"); return 0;}
for(int i=2;i<=n;i++) u[m]=i,v[m--]=i-1;
for(int i=3;i<=n&&m;i++)
for(int j=i-2;j&&m;j--) if(gcd(i,j)==1) u[m]=i,v[m--]=j;
if(m){ puts("Impossible"); return 0;}
puts("Possible");
for(int i=1;u[i];i++) printf("%d %d\n",u[i],v[i]);
return 0;
}

  

CodeForces - 1009D Relatively Prime Graph的更多相关文章

  1. codeforces 1009D Relatively Prime Graph【欧拉函数】

    题目:戳这里 题意:要求构成有n个点,m条边的无向图,满足每条边上的两点互质. 解题思路: 显然1~n这n个点能构成边的条数,就是2~n欧拉函数之和(x的欧拉函数值代表小于x且与x互质的数的个数. 因 ...

  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 459E Pashmak and Graph(dp+贪婪)

    题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...

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

  5. Relatively Prime Graph CF1009D 暴力 思维

    Relatively Prime Graph time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. ACM - 最短路 - CodeForces 295B Greg and Graph

    CodeForces 295B Greg and Graph 题解 \(Floyd\) 算法是一种基于动态规划的算法,以此题为例介绍最短路算法中的 \(Floyd\) 算法. 我们考虑给定一个图,要找 ...

  7. 【Codeforces 1009D】Relatively Prime Graph

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 1000以内就有非常多组互质的数了(超过1e5) 所以,直接暴力就行...很快就找完了 (另外一开始头n-1条边找1和2,3...n就好 [代 ...

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

  9. [Codeforces 1178D]Prime Graph (思维+数学)

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

随机推荐

  1. c++都忘记了,看了看那本发黄的C++primer,还是要去翻下了

    char *s="string"和char s[]="string"的区别 void main() { char* pStr1 = "Hello!&q ...

  2. [CodePlus 2017 11月赛]晨跑 题解(辗转相除法求GCD)

    [CodePlus 2017 11月赛]晨跑 Description "无体育,不清华"."每天锻炼一小时,健康工作五十年,幸福生活一辈子".在清华,体育运动绝 ...

  3. yii2-widget-fileinput英文文档翻译

    源地址:http://plugins.krajee.com/file-input 该插件是为bootstrap开发的增强版h5文件上传插件,具有多文件预览,多文件选择等功能.该插件提供了基于boots ...

  4. Thinkphp的CURD

    CURD即(Create Update Read Delete)其实也就是等同于增删改查. C:Create 创建数据  对数据的添加 Create$m=new Model('User');$m=M( ...

  5. MYSQL的隐式类型转换

    官方文档中是这么说的 当操作者使用不同类型的操作数,操作数类型兼容的出现使 转换.一些 发生隐式转换.例如,MySQL会自动 将数字转换为字符串的必要,反之亦然. 也可以将数字转换为字符串明确 使用( ...

  6. [Leetcode] Sum 系列

    Sum 系列题解 Two Sum题解 题目来源:https://leetcode.com/problems/two-sum/description/ Description Given an arra ...

  7. 32.Longest Valid Parentheses---dp

    题目链接:https://leetcode.com/problems/longest-valid-parentheses/description/ 题目大意:找出最长的括号匹配的子串长度.例子:&qu ...

  8. UVA 1103 How Many O's?

    题目链接:UVA-11038 题意为给定n和m,求n和m之间(包含)的所有数包含的0的个数. 思路是,用cal(x)表示小于等于x的数包含的0的个数.则答案为cal(n)-cal(m-1). 再把求c ...

  9. learnyounode 题解

    //第三题 var fs =require('fs')var path=process.argv[2]fs.readFile(path,function(err,data){ var lines=da ...

  10. leetcode Two Sum II - Input array is sorted <面试常考题>

    题目描述 //二分查找的变形   用头尾两个指针进行  面试考察题 class Solution { public: vector<int> twoSum(vector<int> ...