← All problemsSign in

GCD Summation

CodeChefRating 1639Open on judge ↗

For an array $A$ of length $N$, we define $f(A)$ to be the sum of [GCD](https://en.wikipedia.org/wiki/Greatest_common_divisor)s of its adjacent elements, i.e. $$ f(A) = \sum_{i=1}^{N-1} \gcd(A_i, A_{i+1}) $$ --- You are given two integers $N$ and $K$. Find any array $A$ of length $N$, consisting of **distinct integers** between $1$ and $10^9$, such that $f(A) = K$. If multiple valid arrays

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