Relatively Prime Graph CodeForces - 1009D

Relatively Prime Graph

题目链接:CodeForces - 1009D

题意:定义一个relatively prime graph:每条边的两端点的GCD是1,且图中无自环的连通图;现在给出点的个数n,边的个数m,问能否构建一个relatively prime graph;

图是连通的,m>=n-1;

由1开始找比他大的互质数,直到找到m条;

看上是O(n^2logn)的复杂度,其实不然,如果能找到m条边,就是年找到m对互质数,复杂度远到不了O(n^2logn),n=1000时区间[1, n]中的互质数就大约10000个了;

#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
	return b==0?a:gcd(b, a%b);
}
struct node{
	int u, v;
}edge[100010];
int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	int e=0;
	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(gcd(i, j)==1){
				edge[e].u=i;
				edge[e++].v=j;
			}
			if(e==m) break;
		}
		if(e==m) break;
	}
	if(e<m||m<n-1) printf("Impossible\n");
	else{
		printf("Possible\n");
		for(int i=0; i<e; i++){
			printf("%d %d\n", edge[i].u, edge[i].v);
		}
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Quasi-polynomial mapping-based root-finder is a numerical method used to find the roots of a given polynomial equation. It is an iterative method that uses a quasi-polynomial mapping function to transform the polynomial equation into a linear equation. The method works by iteratively solving the linear equation until the root of the original polynomial equation is found. The quasi-polynomial mapping function is a polynomial function of two variables that maps the complex plane to itself. The function is defined as follows: f(z) = z^d + a_1(z)z^(d-1) + a_2(z)z^(d-2) + ... + a_d-1(z)z + a_d(z) where d is the degree of the polynomial equation, a_i(z) are polynomial functions of z of degree at most d-i, and z is a complex variable. To use the quasi-polynomial mapping-based root-finder, the following steps are performed: 1. Choose an initial guess for the root of the polynomial equation. 2. Apply the quasi-polynomial mapping function to the initial guess. 3. Solve the resulting linear equation for the new value of the guess. 4. Repeat steps 2 and 3 until the difference between successive guesses is less than a specified tolerance. The quasi-polynomial mapping-based root-finder has the advantage of being able to find multiple roots of a polynomial equation, including roots with multiplicity greater than one. It is also relatively fast and efficient compared to other root-finding methods. However, it may not always converge to the correct root, particularly for polynomial equations with multiple roots that are close together.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值