回帰の混乱

最近トップコーダーのアルゴリズム問を解きながら苦労しました。I correctly deduced that the problem had an embedded recursive structure: to flip the ith light switch off meant, in order for the problem to be solved, all light switches at multiple indices needed to be on. Thus, it might make sense to recursively call the flip on the first multiple that is off, passing "off" instead of "on", akin to an alpha-beta pruning search algorithm for chess game trees. しかし対称があるから貪欲な方法が使える。 Making multiple passes, flipping the leftmost Y and all its multiples on each pass, should suffice.