Editorial for COCI '09 Contest 4 #3 IKS
Submitting an official solution before solving the problem yourself is a bannable offence.
Let us examine one arbitrary prime, . How many times can you divide the sequence with
? Obviously, the smallest number of times you can divide each number in sequence with
. Suppose we know for each number in sequence number
which indicates the number of times we can divide the
number in the sequence by
. Dividing one number with
and multiplying some other number with
now turns into decreasing/increasing corresponding
's. Since our goal is to maximize the smallest
, it's quite obvious that the best thing to do is always take one away from the largest
and add it to the smallest, until all
's are equal or almost equal (they can be off by at most one). It can be easily seen now that the solution for each
is equal to the sum of all
's for the corresponding
divided by the number of elements, rounded down.
Using the sieve of Eratosthenes for fast prime number generation solves this task under given constraints.
Comments