Approach hintTry it first, then revealHide
Sorted by value, a beautiful array is a chain in which each element divides the next. Let dp[v] be the longest chain ending at value v and push it forward to every multiple of v, a harmonic sum of O(M log M).