Help understand the solution of round 257 (div 1 D) — Jzzhu and Numbers

Revision en1, by Wildebeest, 2017-05-23 09:40:21

I was trying to solve this problem for several days. I failed and read the editorial. But I couldn't understand the solution. Can someone please explain how they came up with that formula?

Thanks in advance :)


  Rev. Lang. By When Δ Comment
en1 English Wildebeest 2017-05-23 09:40:21 375 Initial revision (published)