← All problemsSign in

Permutation and Modulus

CodeChefRating 1141Open on judge ↗

Given an integer $N$, find a permutation $P = P_1, P_2, \ldots, P_N$ of length $N$ that satisfies the following two conditions: - $P_i \neq i$ $(1 \leq i \leq N)$; - Consider the set which contains $P_i$ $\%$ $i$ for all $1 \leq i \leq N$. This set should have the **minimum** number of **distinct** integers possible, over all permutations $P$. Note that a permutation of length $N$ is an array con

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