Orac and Models
MediumRating 1400Codeforces1-D Dynamic Programming
Approach hintTry it first, then revealHide
Let dp[i] be the longest beautiful sequence ending at index i. Push each dp[i] forward to the multiples 2i, 3i, ... that have a larger size; the harmonic series makes this O(n log n).