# UVa 10023

 This is a stub or unfinished. Contribute by editing me.

## Square Root

Big Numbers

Big numbers are to be implemented to resolve this problem. The operations of multiplication and half part are enough for this purpose.

Big Numbers Multiplication

Assuming it is easy to sum up big numbers and to multiply them by an number of the form ${\displaystyle 2^{n}}$, n being an integer, it becomes a trivial task to execute multiplication above these numbers.

To accomplish this task we shall consider two big numbers, a and b, which, represented as an array of integers (the least significant digit at the left) would appear as:

${\displaystyle a=(a_{0},a_{1},a_{2},...,a_{m}-_{1})),b=(b_{0},b_{1},b_{2},...,b_{n}-_{1})}$

If both numbers are divided in half so that:

${\displaystyle a=(AB),b=(CD),}$ (A, B, C, D are big numbers array representations),

we would notice that:

${\displaystyle a=A+2^{x}.B,b=C+2^{y}.D,}$ x = digit count of a, y = digit count of b

Therefore the product sought would be so that:

${\displaystyle a.b=A.C+2^{y}.A.D+2^{x}.B.C+2^{x}.2^{y}.B.D}$

Make x = y.

${\displaystyle a.b=A.C+2^{x}.(A.D+B.C)+2^{x}.2^{y}.B.D}$

${\displaystyle a.b=}$

Then the recursive aproach shall take ${\displaystyle O(n.log(n))}$ steps to solve the problem. The argument is based on solving the recurrence s(n) such that:

${\displaystyle s(n)=2.s(n-1)+k.n,}$ being k a constant factor.

This recurrence represents the number of time steps taken to solve the problem since two multiplications which take ${\displaystyle s(n-1)}$ are held and the sum operations are of about ${\displaystyle k.n}$ steps.

Of course, the number n itself is of the order of ${\displaystyle 2^{x}}$, the x would be such that ${\displaystyle x=O(log(n))}$. Then the final time amount taken to multiply those numbers together is of ${\displaystyle O(log(n).log(log(n)))}$.

Square Root Algorithm

A simple but effective square root algorithm is based on a binary search of the numbers from 1 to n.

In pseudo-code:

```integer sqrt(integer n) {
integer a, b, m;
a:= 1;
b:= n;
loop {
m:= (a+b)/2;
if (m = a || m = b) return m;
if (m*m > n) a:= m;
else b:= m;
}
}
```

Solution

Solution to this problem is a simple combination of the two above algorithms.

--Schultz 14:35, 14 Nov 2006 (EST)