1 #include<stdio.h> 2 #include<string.h> 3 #define N 50050 4 int s[N]={0},a[N],vis[N]; 5 int hash(int x) 6 { 7 int y=(x%N+N)%N; 8 while(vis[y]&&s[y]!=x) 9 y=(y+1)%N; 10 return y; 11 } 12 int insert(int x) 13 { 14 int y=hash(x); 15 vis[y]=1; 16 s[y]=x; 17 } 18 int find(int x) 19 { 20 return vis[hash(x)]; 21 } 22 int main() 23 { 24 int n,i,j; 25 while(~scanf("%d",&n)) 26 { 27 memset(vis,0,sizeof(vis)); 28 for(i=0;i<n;i++) 29 { 30 scanf("%d",&a[i]); 31 insert(a[i]); 32 } 33 int sum=0; 34 for(i=0;i<n;i++) 35 { 36 for(j=i+1;j<n;j++) 37 { 38 if(a[i]&&a[j]&&find(a[i]+a[j])==1) 39 sum++; 40 } 41 } 42 printf("%d ",sum); 43 } 44 }