← All problemsSign in

Beautiful Array

CodeChefRating 2671Open on judge ↗

You're given an array $A$ of $N$ integers. You need to find the minimum cost of creating another array $B$ of $N$ integers with the following properties - $B_i \ge 0$ for each $1 \leq i \leq N$ - The GCD of adjacent elements of $B$ is equal to $1$, i.e, $\gcd(B_i, B_{i+1}) = 1$ for each $1 \leq i \lt N$ The cost of creating $B$ is defined as follows: $$ \sum_{i=1}^{N} 2^{|A_i - B_i |} $$ Find

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start