The main idea: to tell an integer n decomposition to two prime number of the scheme.
The topic thought: The prime number hits the table, after traverses the 1-N/2, looks for the scheme count, needs to note is: C/S, the bool type occupies one byte, the int type occupies 4 bytes, in the Prime number dozen table uses the bool type to save a lot of memory.
#include <iostream>#include<algorithm>#include<cstring>#include<vector>#include<stdio.h>#include<queue>#include<math.h>#defineINF 0x3f3f3f3f#defineMAX 10000005#defineTemp 10000005using namespacestd;intp[664589],cnt=0;BOOLVis[max];voidGetprime ()//Prime number playing table{memset (Vis,false,sizeof(VIS)); Memset (P,0,sizeof(p)); for(intI=2; i<max;i++) { if(!Vis[i]) {p[++cnt]=i; for(intj=i+i;j<max;j+=i) {vis[j]=true; } } }}intMain () {getprime (); intn,t,sum,cns=0; scanf ("%d",&T); while(t--) {sum=0; scanf ("%d",&N); for(intI=1;p [i]<=n/2; i++)//number of traversal search scenarios { if(vis[n-p[i]]==false) Sum++; } printf ("Case %d:%d\n",++cns,sum); } return 0;}
View Code
Lightoj 1259 Goldbach ' s conjecture prime number playing table