Gregorian Calendar

I was trying to solve the Beginners level problem Gregorian Calendar but failed to solve it. Then I refer to the sibmissions but didn’t get the logic used by other people. Can anyone explain me the logic used in the solution of that problem. The link of the problem is given below

You can check this solution code
the key point here is to check the number of leap years between the two given years