It's very simple. Using the binary search algorithm to first find the first number, then second.

The difference of their indices will be sought. In zavimosti on the exact definition may need to clean the unit.

I suspect that the language Pascal. Then the code search will be similar to that.

\r

{foo — the desired quantity. a and b — the border of the search}

procedure Find(foo: integer; a: integer; b: integer);

var c: integer;

begin

if (b-a) > 1 then

begin

c:= (a+b) div 2;

find(foo,a,c);

find(foo,c,b);

end else

begin

if (array_[a] = foo) then Result := a;

if (array_[b] = foo) then Result := b;

end;

end;