#include<iostream>
#include"array.h"
using namespace std;
#define SUCCESS 1
#define FAIL 0
static int result = 0;
int find(int *a , int p , int q , int r , int x)
{
int n1 = q - p + 1;
int n2 = r - q;
int *b = (int *)malloc(sizeof(int)*n1);
copyArray(a , b , p , q);
int *c = (int *)malloc(sizeof(int)*n2);
copyArray(a , c , q + 1 , r);
for(int i = 0 ; i < n1 ; i++ )
{
if(indexOf(c ,n2 , x - b[i]) != -1)
return SUCCESS;
}
return FAIL;
}
int findDivition(int *a , int p , int q , int x)
{
if(p < q)
{
int r = (p + q)>>1;
findDivition(a , p , r , x);
findDivition(a , r + 1 , q , x);
return result += find(a , p , r , q , x);
}
}
int main()
{
int a[10] = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10};
cout<<findDivition(a , 0 , 9 , 20);
system("pause");
}