Sei sulla pagina 1di 5

Maximal Multiplication Of All Possible

Summands
Michael Ioshpe
January 24, 2015

Abstract
Given a natural number, we give it's precise decomposition to summands
whose multiplication is maximal. We present two solutions, the rst is
purely computational, whereas the second uses pure-mathematical tools.
This problem and it's solution(s) is a classical example to the phenomena where (pure) mathematics gives an easy solution to an algorithmic
problem.

Introduction and statement

Let

nN

a (positive) natural number. One can write

is the number of summands, and

xi

n = x1 + ... + xk ,

where

are natural positive numbers, henceforth

the summands.
Both

and

xi

are considered as variables, i.e. one can change both the number

of summands and the summands themselves to get dierent decompositions.


Now, the main question of our discussion is the following:
The Main Question: what is the decomposition of a natural number to summands whose multiplication is maximal?
To answer The Main Question, we consider two approaches - purely computational one, and purely mathematical one.

A computational approach

The Main Question has the obvious solution - run over all possible decompositions and nd the one with maximal multiplication. We describe this in detail:

2.1

The Main Algorithm:

Fix two arrays of length

n;

one will hold the maximal decomposition and the

other a temporary decomposition. Also x two integers - the maximum (which


is given default value

n),

and the current number of summands.

Now, for each 1 k n (a


Rec(iter, num) as follows:

current number of summands), call the recursion

(i) In each iteration, call the recursion with the current iteration-number and

Rec(k, n)).
num in the

the current sum (e.g., at rst one calls


(ii) If this is the last iteration, put

last place of the array and

compute the multiplication of the current decomposition.


(iii) Otherwise, for each

1 a n,

call

Rec(iter 1, num a).

To sum up, The algorithm puts in each iteration the next element of the decomposition, and in the last iteration the value that gives the needed sum.
Via recursion one easily sees that all the possible decompositions are being
reached (more than once).
Now, one easily sees the huge problem - the complexity of this algorithm is
absurd! Moreover, the use of O(n) space seems rather irritating.
See section 4 for some statistics.
Remark: Note that this algorithm is the most naive one; modications can be
made, but the purpose of this paper is to show that this is unnecessary - We
look for a (much) simpler solution.

A Mathematical Approach

We now present a theoretical solution, involving no computational aspects.


The philosophy is as follows - give a mathematical way to nd the precise
decomposition and the maximal multiplication, as an explicit function of n;
then, if the formula is 'nice' enough, simply write the code.
The solution involves nding maxima in multivariable-functions and some elementary linear algebra.

3.1
Fix

Determine the summands

n;

for each (xed)

k,

dene:

(x1 , ..., xk ) = x1 ... xk


Thus, our problem is to nd this function's maximum (when

xi 6= 0),

to the constraint

x1 + ... + xk = n
In other words, we have:

(x1 , ..., xk1 ) = x1 ... xk1 (n x1 ... xk1 )


The partial derivatives are

=
xj (n x1 ... xk1 xi )
xi
j6=i

Thus we get

thatO = 0

when:

subject

2
1

...
1

1 ...
2 ...
... ...
1 ...

x1
n
1
x2 n
1
=

... ... ...


xk1
n
2

This matrix is invertible, so the system has precisely one solution.

On the

n
...
xk =
is a solution. Thus, x1
k
is the solution; the kind reader will check that this is a maximal

other hand, one easily sees that

xi =

n
... nk
k
point, e.g. by the Hessian criterion.

To sum up, we see that for a (real-valued) decomposition to give a maximal


multiplication, it's summands must be the same. This is true, in a way, in the
natural-valued case as well.
Note that this already gives a far-better algorithmic approach then the one
discussed above.
Now we have to nd the optimal k.

3.2

Optimal number of summands

We see that, subject to our restriction, the function

(x1 , ..., xk ) = x1 ... xk


gets the form:

Where we want to nd the

n
(k) = ( )k
k
optimal k 1.

The derivative is,

d
n
n
= ( )k (log(( ) 1)
dk
k
k
= e, i.e.k = ne (say n 3).

n
k
Again, by the second derivative test, one veries that this is a maximal point.
This is zero when

Since it is unique, this is precisely the global maximum.

n to real summands of
n
'times', and the maximal
e

This settles the real-valued case: The decomposition of


maximal multiplication is precisely
multiplication is

3.3

e + e + ... + e,

ee.

Back to

Recall that the original problem was to nd a natural-valued decomposition. To


do so, Note that we need to nd the closest natural point

(n1 , ..., nk ) to (e, ..., e).

This in turn depends on the remainder of division of n by 3.

Note that the

optimal scenario is to have as many 3's as possible.


The precise solution is the following:
(i) Remainder 0: This is the easiest case, since the decomposition

3 + ... + 3

times) holds.
(ii) Remainder 2: The decomposition

3 + ... + 3 + 2

holds and is optimal.

n
3

(iii) Remainder 1: This is the hardest case. We have two natural candidates,

3 + ... + 3 + 1

and

3 + ... + 3 + 2 + 2.

But since

(3 e)2 + (e 1)2 > 2(e 2)2 ,

the latter is the optimal.


To sum up, The precise decomposition of a natural number

n to summands with

maximal multiplication is the following:

3|n
3 + ... + 3
3 + ... + 3 + 2 + 2 3|n 1

3 + ... + 3 + 2
3|n 2
And the maximal multiplication is:

n
0

3 3 2
n1
3 3 1 22

n2
3 3 21

3|n
3|n 1
3|n 2

Summary and statistics

To sum up, we see that no computational algorithm is needed. The most ecient
solution is given by pure mathematical aspects.
Here is the comparison of the running times of the two algorithms:

15

20

22

24

26

28

30

32

Computational algorithm's times (sec)

0.047

0.234

0.938

3.75

16.897

72.417

325.376

Mathematical Algorithm's times (sec)

And here is the graph:

Figure 1: Computational & Mathematical Algorithm's Running Times

Potrebbero piacerti anche