Jamie and Interesting Graph CodeForces - 916C
http://codeforces.com/problemset/problem/916/C
好尬的题啊。。。
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<vector> 5 using namespace std; 6 #define fi first 7 #define se second 8 #define mp make_pair 9 #define pb push_back 10 typedef long long ll; 11 typedef unsigned long long ull; 12 typedef pair<int,int> pi; 13 struct E 14 { 15 int u,v,w; 16 }e[100100]; 17 int ne; 18 int n,m; 19 bool nprime[200100]; 20 int prime[100100],len; 21 int x=1,y=2; 22 int main() 23 { 24 int i,j,t; 25 nprime[1]=1; 26 for(i=2;i<=200000;i++) 27 { 28 if(!nprime[i]) prime[++len]=i; 29 for(j=1;j<=len&&i*prime[j]<=200000;j++) 30 { 31 nprime[i*prime[j]]=1; 32 if(i%prime[j]==0) break; 33 } 34 } 35 scanf("%d%d",&n,&m);m-=(n-1); 36 for(i=1;i<n;i++) e[++ne]=(E){i,i+1,1}; 37 for(i=1;i<=m;i++) 38 { 39 if(y==n) x++,y=x+2; 40 else y++; 41 e[++ne]=(E){x,y,1000000000}; 42 } 43 for(t=0;nprime[t+n-1];t++); 44 e[1].w+=t; 45 printf("%d %d\n",t+n-1,t+n-1); 46 for(i=1;i<=ne;i++) printf("%d %d %d\n",e[i].u,e[i].v,e[i].w); 47 return 0; 48 }