Yet Another Number Sequence

CodeForces - 392C