题目:戳这里

题意:要求构成有n个点,m条边的无向图,满足每条边上的两点互质。

解题思路:

显然1~n这n个点能构成边的条数,就是2~n欧拉函数之和(x的欧拉函数值代表小于x且与x互质的数的个数。

因此m>n-1 && m <= sum成立则可以构成无向图。

接着求出1e5以内的欧拉函数,求和可以发现前1000项的欧拉值就已经远远大于1e5。

所以m条边直接两层循环暴力即可。

附本人代码:

 1 #include <bits/stdc++.h>
2 typedef long long ll;
3 const int maxn = 1e5+10;
4 const ll inf = 1e18;
5 const ll mod = 1e9+7;
6 using namespace std;
7 ll cnt[maxn];
8 ll euler[maxn];
9 void geteuler() {
10 memset(euler, 0, sizeof(euler));
11 euler[1] = 1;
12 for(ll i = 2; i < maxn; ++i) {
13 if(!euler[i]) {
14 for(ll j = i; j < maxn; j+=i) {
15 if(!euler[j]) euler[j] = j;
16 euler[j] = euler[j]/i * (i - 1ll);
17 }
18 }
19 }
20 }
21 ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
22 int main(){
23 ll n, m;
24 ll sum = 0;
25 scanf("%lld %lld", &n, &m);
26 geteuler();
27 for(ll i = 2; i <= n; ++i) {
28 sum += euler[i];
29 }
30
31 // printf("%lld\n", sum);
32 if(sum < m || m < n - 1) {
33 puts("Impossible");
34 return 0;
35 }
36 puts("Possible");
37 for(ll i = 1; i <= n; ++i) {
38 for(ll j = i + 1; j <= n; ++j) {
39 if(gcd(i,j)==1) {
40 printf("%lld %lld\n", i, j);
41 --m;
42 if(!m) return 0;
43 }
44 }
45 }
46 return 0;
47 }

codeforces 1009D Relatively Prime Graph【欧拉函数】的更多相关文章

  1. Codeforces 906D Power Tower(欧拉函数 + 欧拉公式)

    题目链接  Power Tower 题意  给定一个序列,每次给定$l, r$ 求$w_{l}^{w_{l+1}^{w_{l+2}^{...^{w_{r}}}}}$  对m取模的值 根据这个公式 每次 ...

  2. CodeForces - 1009D Relatively Prime Graph

    题面在这里! 直接暴力找点对就行了,可以证明gcd=1是比较密集的,所以复杂度略大于 O(N log N) #include<bits/stdc++.h> #define ll long ...

  3. Codeforces 1114F Please, another Queries on Array? [线段树,欧拉函数]

    Codeforces 洛谷:咕咕咕 CF少有的大数据结构题. 思路 考虑一些欧拉函数的性质: \[ \varphi(p)=p-1\\ \varphi(p^k)=p^{k-1}\times (p-1)= ...

  4. Codeforces Round #538 (Div. 2) F 欧拉函数 + 区间修改线段树

    https://codeforces.com/contest/1114/problem/F 欧拉函数 + 区间更新线段树 题意 对一个序列(n<=4e5,a[i]<=300)两种操作: 1 ...

  5. CodeForces - 645F:Cowslip Collections (组合数&&欧拉函数)

    In an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning t ...

  6. Codeforces 871D Paths (欧拉函数 + 结论)

    题目链接  Round  #440  Div 1  Problem D 题意   把每个数看成一个点,如果$gcd(x, y) \neq 1$,则在$x$和$y$之间连一条长度为$1$的无向边.   ...

  7. Codeforces 1114F(欧拉函数、线段树)

    AC通道 要点 欧拉函数对于素数有一些性质,考虑将输入数据唯一分解后进行素数下的处理. 对于素数\(p\)有:\(\phi(p^k)=p^{k-1}*(p-1)=p^k*\frac{p-1}{p}\) ...

  8. Please, another Queries on Array?(Codeforces Round #538 (Div. 2)F+线段树+欧拉函数+bitset)

    题目链接 传送门 题面 思路 设\(x=\prod\limits_{i=l}^{r}a_i\)=\(\prod\limits_{i=1}^{n}p_i^{c_i}\) 由欧拉函数是积性函数得: \[ ...

  9. Codeforces 776E: The Holmes Children (数论 欧拉函数)

    题目链接 先看题目中给的函数f(n)和g(n) 对于f(n),若自然数对(x,y)满足 x+y=n,且gcd(x,y)=1,则这样的数对对数为f(n) 证明f(n)=phi(n) 设有命题 对任意自然 ...

随机推荐

  1. REUSE_ALV_FIELDCATALOG_MERGE函数

    今天使用REUSE_ALV_FIELDCATALOG_MERGE函数,就是获取不到fieldcat, 搞了半天才发现,原来参数要全部大写才行!!小写字符就是获取不到,唉,悲哀...

  2. 03--Docker 容器和镜像常用命令

    一.帮助命令 docker version docker info docker --help =====================镜像命令=========================== ...

  3. LeetCode-P53题解【动态规划】

    本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: https://leetcode.com/problems/maximum-subarray/ ...

  4. 两节锂电池充电芯片,和保护IC的接法

    1.两节锂电池的充电电路:可以分为三种方式. 第一种,USB口的5V输入,使用一颗SOT23-6的升压IC,直接升压到8.4V.电流在1A以下.优点是成本最低,缺点是,没有锂电池充电控制逻辑,和锂电池 ...

  5. ryu—流量监视

    1. 代码解析 ryu/app/simple_monitor_13.py: from operator import attrgetter from ryu.app import simple_swi ...

  6. Redis 实战 —— 08. 实现自动补全、分布式锁和计数信号量

    自动补全 P109 自动补全在日常业务中随处可见,应该算一种最常见最通用的功能.实际业务场景肯定要包括包含子串的情况,其实这在一定程度上转换成了搜索功能,即包含某个子串的串,且优先展示前缀匹配的串.如 ...

  7. logging philosophy 日志哲学

    Go kit - Frequently asked questions https://gokit.io/faq/ Logging - Why is package log so different? ...

  8. SpringMVC听课笔记(四:映射请求参数 & 请求头)

    1.请求参数 @RequestParam  来映射请求参数  http://localhost:8080/springmvc-1/springmvc/testRequestParam?username ...

  9. docker基本使用-常用命令

    一. 常用命令 #查看docker服务 docker ps #启动docker服务 systemctl start docker #查看本地镜像 docker images #删除本地镜像 docke ...

  10. 基于Vue+ElementUI架构的前端国际化解决方案

    1.项目目录结构 ├── build                      构建相关配置文件 |     |── index.js             webpack的基础配置入口 ├── m ...