链接: http://codeforces.com/contest/1178
D. Prime Graph(构造)
题面:
Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn’t think of anything inventive. Hence, he will be giving her a graph. How original, Bob! Alice will surely be thrilled!
When building the graph, he needs four conditions to be satisfied:
It must be a simple undirected graph, i.e. without multiple (parallel) edges and self-loops.
The number of vertices must be exactly n — a number he selected. This number is not necessarily prime.
The total number of edges must be prime.
The degree (i.e. the number of edges connected to the vertex) of each vertex must be prime.
Below is an example for n=4. The first graph (left one) is invalid as the degree of vertex 2 (and 4) equals to 1, which is not prime. The second graph (middle one) is invalid as the total number of edges is 4, which is not a prime number. The third graph (right one) is a valid answer for n=4.
题意: 让你构造有n个点的图,使总边数是质数,每一个节点的度数也是质数
思路: 首先有一个性质就是n~(n+n/2)肯定存在一个质数,所以我们可以先把所有点连接起来构造一个环,接着让前n/2个节点与后n/2个节点相连,这样就构成了符合条件的图,每个点的度数为2或3,且总边数为质数
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
bool prime(int x)
{
if(x<2)
return 0;
for(int i=2