← All problemsSign in

Permutation GCD

CodeChefRating 1328Open on judge ↗

Chef is interested in the sum of [GCD](https://en.wikipedia.org/wiki/Greatest_common_divisor)s of all prefixes of a permutation of the integers $\{1, 2, \ldots, N\}$. Formally, for a permutation $P = [P_1, P_2, \ldots, P_N]$ of $\{1, 2, \ldots, N\}$, let us define a function $F_i = \gcd(A_1, A_2, A_3, \ldots, A_i)$. Chef is interested in the value of $F_1 + F_2 + \ldots + F_N$. Now, Chef wants t

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