This is on the basis of one of the most famous IT interview questions covered by Presh Talwalkar on his YouTube Channel. Presh, is one of the most influential guys on Maths/Logic in the mordern era.
However, Presh doesnt break it down as an IT guy. We will use a step by step analysis to get to the correct answer.
You can watch the video here: https://youtu.be/H4YjOD65Ur0
For those who still want to make the code more efficient there is an Advanced branch with basic Math logic to further help you short circuit your code. We are only increasing efficiency here via logic.
As the image shows... Click on "main" and you will notice a dropdown list with all the branches. You can select which ever step you need from there. But please go step by step.
