← All problemsSign in

Querified

CodeChefRating 2787Open on judge ↗

You are given a tree on $N$ vertices. The tree is rooted at vertex $R$. For each $u$ from $1$ to $N$, we define the value $G_u$ as follows: - $G_u$ is the **maximum** value of $\gcd(u, v)$ across all vertices $v \lt u$ that lie in the subtree$^\dagger$ of $u$. If no vertex with a label smaller than $u$ lies within its subtree, $G_u$ is defined to be $-1$ instead. Compute all the $N$ values $G_

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