Unable to solve Gadget Fan (February 17 Easy — hackerearth)

Revision en1, by Bob_and_Vagene, 2017-02-06 18:28:50

link to the problem : https://www.hackerearth.com/practice/math/combinatorics/inclusion-exclusion/practice-problems/algorithm/gadget-fan/description/

I am only able to get 68 points when i submitted an O(n) solution. I am not able to optimize it further. I read the editorial as well but i wasn't able to understand it. So, if anyone could explain me the editorial or provide an alternate efficient approach to this problem.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Bob_and_Vagene 2017-02-06 18:28:50 490 Initial revision (published)