Codeforces 1178D. Prime Graph

Portal

First, each must have at least two edges connected to point

So easy to think first and then slowly to ensure that bordered

Then the first to form a ring: $ (1,2), (2,3), (3,4) ... (n, 1) $ 

Then consider the plus side, find a point plus one side or legitimate, then it may direct $ (1,4), (2,5), (3,6) $, and then once the number of sides is prime output directly answer

So the question now is whether guaranteed $ [n, n + \ left \ lfloor \ frac {n-3} {2} \ right \ rfloor] $ there must be a prime number in the range of

Make a list found in the $ n \ in [3,1000] $ is not within the sole legitimate only $ n = 4 $, then special judge on the line ......

Official explanations turned out this operation? ? ? No proof of it? ? ?

 

 

 

 

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
    return x*f;
}
const int N=1e5+7;
int n,m;
struct edge {
    int u,v;
    edge (int _u=0,int _v=0) { u=_u,v=_v; }
};
vector <edge> ans;
inline void ins(int u,int v) { ans.push_back(edge(u,v)); }
int pri[N],tot;
bool not_pri[N];
void pre()
{
    not_pri[1]=1;
    for(int i=2;i<=2*n;i++)
    {
        if(!not_pri[i]) pri[++tot]=i;
        for(int j=1;j<=tot;j++)
        {
            ll g=1ll*i*pri[j]; if(g>2*n) break;
            not_pri[g]=1; if(i%pri[j]==0) break;
        }
    }
}
int main()
{
    n=read(); pre();
    for(int i=2;i<=n;i++) ins(i,i-1);
    ins(1,n); int now=n;
    if(n==4) ins(1,3),now++;
    else
        for(int i=1;i<=n-3;i++)
        {
            if(!not_pri[now]) break;
            if(i&1) ins(i,i+3),now++;
        }
    if(not_pri[now]) { printf("-1\n"); return 0; }
    printf("%d\n",now);
    for(auto E: ans) printf("%d %d\n",E.u,E.v);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/LLTYYC/p/11607039.html