← All problemsSign in

Tree GCD

Vaga is famous for embarrassing his friends by giving them tough questions to solve. This time Vaga gave a question to Abhi. Abhi decided to take revenge on him. Can you help him bring Vaga back to ground ? Given a tree of N nodes rooted at node 1, each node has a value associated with it . For each node x , how many nodes in its subtree( excluding the node x itself ) have gcd( valsubtree node,va

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