Hackerrank doubts

How to solve this sum.Please help me in the logic and implemetation