This is an easy problem.
when we solve problem there are something to be considered.
I will tell you one tip.
1. from small number to Big number
- problem give us find big number for example sum of over 10^14. just find the answer of smaller number ex) 10^3, 10^4 and check your logic if it is working fine.
I solve this problem by using dp.