codeforces-1009D Relatively Prime Graph

泛微OA与金蝶云星空深度集成实战:审批与表单双场景解析 本文深入解析泛微OA与金蝶云星空的深度集成实战,聚焦审批流程与表单对接两大核心场景。通过具体案例,详细阐述了如何实现业务数据与审批流程的自动联动,打破数据孤岛,提升企业运营效率与数据一致性,并分享了接口设计、安全策略及实战避坑指南。 阅读详情

题目链接:http://codeforces.com/problemset/problem/1009/D

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

题意大概就是,给出n,1到n的n个点,问你用m条边连接这n个点可不可行,若不可行,输出“impossible",若可行,输出“possible”,并且给出m条边分别连接的点,限制:每条边连接的两个点必须是互质的。

开始以为什么特殊的数学方法,后来发现直接枚举1到n里的i,j就可以过。

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
pair<int, int> ans[N];

int gcd(int a,int b)    //判断是否互质
{
    if(a<b)
        return gcd(b,a);
    while(b)
    {
        int t=b;
        b=a%b;
        a=t;
    }
    return a;
}

int main() 
{
	int n, m;
	scanf("%d%d", &n, &m);

	if (m < n - 1)     //连接n个点,最少n-1条边
    {
		puts("Impossible");
		return 0;
	}

	int cur = 0;

    for(int i=1;i<=n && cur<m;i++)
        for(int j=i+1;j<=n;j++)
    {
        if(gcd(i,j)==1)
        {
            ans[++cur]=make_pair(i,j);
            if(cur==m)
                break;
        }
    }

	if (cur != m)        //如果所有的互质数的对数不到m,连不成
    {
		puts("Impossible");
		return 0;
	}

	puts("Possible");
	for(int i=1;i<=m;i++)
		printf("%d %d\n", ans[i].first, ans[i].second);

	return 0;
}

 

工业自动化实战:用LabVIEW的DSC模块实现MODBUS-TCP设备控制 本文详细介绍了如何利用LabVIEW的DSC模块实现工业自动化中的MODBUS-TCP设备控制。通过环境准备、核心功能解析、状态机实现及典型工业场景实战,帮助工程师快速掌握稳定可靠的通讯技术,提升工业自动化系统的运行效率。 阅读详情

相关推荐

unity中VideoPlayer播放视频,使用Shader除去黑底且无黑边

1. 创建一个Shader 和 一个 材质球;Shader中复制如下代码:(此Shader代码为“ChromaKeyKit”插件中的ChromaKey_Alpa_Genera代码,但因只需要除去视频黑底而挂一个插件有点不合适) // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' Shader "ChromaKeyKit/ChromaKey/ChromaKey_Alpha_General"

weixin_42065078的博客 1747

Relatively Prime Graph CF1009D 暴力 思维

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 graphG=(V,E)G=(V,E...

weixin_34375233的博客 180

华硕天选3 win11+ubuntu20.04双硬盘双系统配置(包括ubuntu重启后无法成功进入、没有wifi图标的设置)

1、制作系统盘 2、分区 3、重启电脑按F2

baidu_38431960的博客 1万+

Relatively Prime Graph CodeForces - 1009D

Relatively Prime Graph 题目链接:CodeForces - 1009D 题意:定义一个relatively prime graph:每条边的两端点的GCD是1,且图中无自环的连通图;现在给出点的个数n,边的个数m,问能否构建一个relatively prime graph; 图是连通的,m&gt;=n-1; 由1开始找比他大的互质数,直到找到m条; 看上是O(n^...

Sirius_han的博客 275

Unity XR Interaction Toolkit(二)手柄交互

XR Interaction 手柄事件和抓取设置

qq_36608844的博客 8494

Fabric V2.5 通用溯源系统——使用Hyperledger Caliper压力测试

Caliper是一款测试区块链性能的工具,支持Hyperledger Fabric、Ethereum等,支持丰富的测试配置参数,测试完成后将直接输出报告,相较于tape更加专业,但是配置稍微有些复杂。本文将一步一步配置Caliper以测试Fabric V2.5 通用溯源系统中的注册用户、查询用户、农产品上链、农产品查询的区块链性能。

TrueTechLabs 官方博客 1395

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

码农的一亩三分地 457

【26美赛A题】2026美赛数学建模(MCM/ICM)思路解析及代码分享

本文介绍了2026年美赛数学建模A题的解题思路与方法。A题通常属于连续型系统问题,重点在于构建可解释的机理模型,通过将现实机制转化为动态方程进行仿真预测。文章提出了通用建模路线,包括机理抽象、模型假设、动态建模、参数识别、系统仿真和情景预测六个阶段。专栏将提供从机理到方程的系统建模思路、参数标定方法、Python/Matlab实现代码以及高分论文模板。内容适合参加2026美赛A题、偏重物理/工程建模方向的参赛队伍,旨在提升机理建模能力。后续将更新完整题解和源码。

一键难忘的博客 2007

Codeforces ~ 1009D ~ Relatively Prime Graph (构造)

题意构造一个n个点m条边的图,要求:图联通,GCD(u,v)=1,u~v才可以建边。题解由欧拉函数表φ(n)可得,573以内的互素的对数就已经超过1e5了,所以我们暴力枚举即可。#include &lt;bits/stdc++.h&gt; using namespace std; int n, m; vector&lt;pair&lt;int, int&gt; &gt; ans; int main...

张松超的博客 615

基于MATLAB的导弹轨迹和撞击位置仿真

本文将介绍如何使用MATLAB进行导弹轨迹和撞击位置的仿真,提高导弹的精确打击能力。首先,我们需要确定导弹的初始位置和速度,以及导弹所受到的外部环境因素如重力、空气阻力等。在MATLAB中,可以通过ODE求解器来模拟导弹的运动轨迹。最后,我们通过控制器输出的控制信号来控制导弹的姿态。通过对导弹的运动轨迹和姿态进行仿真,可以更好地预测和规划导弹的运动轨迹,提高其精确打击能力。在实际作战中,为了提高导弹精确打击能力,需要对导弹的撞击位置进行预测和规划。我们可以通过控制导弹的姿态来实现撞击目标的精确命中。

CyberLynxO的博客 1982

华为OD机考双机位C卷 - AI处理器组合 (Java & Python & JS & GO & C++ & C)

> 2026华为OD机试双机位C卷 - 华为OD上机考试双机位C卷 华为OD机试双机位C卷真题目录点击查看: [【全网首发】2026华为OD机位C卷 机考真题题库含考点说明以及在线OJ(OD上机考试双机位C卷)](https://blog.youkuaiyun.com/banxia_frontend/article/details/155503868)

算法大师! 233

Codeforces 1009D:Relatively Prime Graph

D. Relatively Prime Graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call an undirected graph G=(V,E)G=(V,E) relatively prime if and onl...

执念 506

基于STM32设计的环境检测系统(OneNet)_365

本项目设计并实现了一种基于STM32F103RCT6单片机的环境检测系统,系统集成了多种传感器模块,具备对环境温湿度、烟雾浓度、易燃气体浓度、一氧化碳浓度和整体空气质量的实时检测功能。系统通过1.44寸SPI接口LCD实现本地数据显示,同时配备有源蜂鸣器用于环境异常报警。在数据通信方面,系统利用ESP8266-WIFI模块,采用MQTT协议将各类传感器数据上传至OneNet云平台,并借助其可视化框架实现网页端可视化界面,可通过电脑和手机浏览器远程访问,实现环境数据的远程监控。该系统设计结构简单、功能全面,适

2189

【Codeforces 1009D】Relatively Prime Graph

【链接】 我是链接,点我呀:) 【题意】 题意 【题解】 1000以内就有非常多组互质的数了(超过1e5) 所以,直接暴力就行...很快就找完了 (另外一开始头n-1条边找1和2,3...n就好 【代码】 #include <bits/stdc++.h> #define ll long long using namespace std; int n,m;...

AWCXV 96

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

D. Relatively Prime Graph codeforces 1009 D

                                                  D. Relatively Prime Graph time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Let'...

JiaYao的博客 251

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

CodeForces 1009 D.Relatively Prime Graph(构造,gcd)

题意: 要求构造n个点m条边的连通图 满足,相连的点的gcd为1(互质) 如果可以,输出Possible和m条边的端点 如果不行,输出Impossible 思路: 首先要保证图连通,至少需要n-1条边,则如果m小于n-1,一定不可能 因为相邻的两个数互质,则可以先建立一条链(1->2,2->3,3->4),一共n-1条边,这样就满足连通了。 然后不足m的边随便加加就行了,直接暴力...

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 223

codeforces 1009 D. Relatively Prime Graph

题意: 构造出一个n个点(编号为1-n) m条边的无向连通图 要求没有自循环边和重边 而且每个边所连的顶点 u v 要求 gcd(u,v)=1 问是否可以构造出这个图,如果可以,输出每个边 思路: 首先欧拉函数判断n个点可以构造 这种图 的最大边数maxm 如果m&lt;=maxm 那就暴力枚举边 #include &lt;cstdio&gt; #include &lt;algo...

qq_36996464的博客 211

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

包子不卖包子 263

CodeForces - 1009D 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) relativel...

pxlsdz的博客 416

CodeForces 1009D Relatively Prime Graph 贪心+枚举

这是一道伪图论题,像我这样的弱鸡,果不其然一上来就被坑了。其实跟图论关系不大,倒是应该好好算算复杂度。m是有限制的,如果输出impossible,必定在枚举的过程中复杂度不大于m的范围。如果有答案,到了m就可以break。毕竟我们从1开始枚举的时候,第一轮枚举下来,肯定是已经得到了一个连通图,放射状的那种,于是丝毫不必担心break的时候图不符合要求的情况。  ...

weixin_39399748的博客 302

CodeForces 1009 D. Relatively Prime Graph(思维)

D. Relatively Prime Graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call an undirected graph G=(V,E)G=(V,E) relatively prime if and onl...

辞树 276

CodeForces - 1009D Relatively Prime Graph

题面在这里! 直接暴力找点对就行了,可以证明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(...

weixin_30887919的博客 70
上一篇: HDU1358 Period
下一篇: CodeForces1010A Fly
「已注销」
博客等级 码龄9年 6粉丝 32原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值