← All problemsSign in

Permutation sum

You are given a permutation $P$ of length $N$. We define $SUM(k, i)$ as sum of the set of numbers {$i, A[i], A[A[i]], A[A[A[i]]], ...,$ } , where $1 \leq i \leq N$ and $ A = P^{k} $, $1 \leq k \leq N$. Let $S$ be the set containing $SUM(k, i)$ for all $1 \leq i \leq N$ and $1 \leq k \leq N$. Print the elements of $S$ in increasing order. Note : A set contains no duplicate elements. ### I

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