Problem 1766 · Hard

Tree of Coprimes

Walk down the tree keeping the stack of ancestors; each node takes its nearest ancestor whose value is coprime with its own.

Open the interactive visualisation