Codeforces Round #708 k-LCM - Construction

Solution:

Simple Problem.

When $k=3$.

If n is a odd number, then the answer is: $a_0=1$, $a_1=\frac{n-1}{2}$, $a_2=\frac{n-1}{2}$.

If $n\ mod\ 4 = 0$, then $a_0=\frac{n}{2}$, $a_1=\frac{n}{4}$, $a_2=\frac{n}{4}$.

Otherwise, n is normal even number, then $a_0=2$, $a_1=\frac{n-2}{2}$, $a_2=\frac{n-2}{2}$.

When $k>3$, we just fill up the array with 1 until last 3 elements.

Code:

Submission #111267135 - Codeforces
Codeforces. Programming competitions and contests, programming community
DigitalOcean Referral Badge 蜀ICP备19018968号