int SearchInsert(int A[], int n, int target) {
if(n==0)return 0;
if(A[n-1] < target) return n;
int low = 0;
int high = n-1;
int mid ;
while(1)
{
mid = (low + high)/2;
if(low >= high) break;
if (A[mid] < target)
low = mid +1;
else
high = mid;
}
return mid;
}
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
int A[] = {2,3,5,7,11,13,17};
int target = 8;
cout << SearchInsert(A, 7, target);
return 0;
}