The goal is as follows:
In the Gregorian calendar, the year is a leap year in two cases: either it is a multiple of 4, but not a multiple of 100, or a multiple of 400.
Implement a method that calculates the number of leap years from the beginning of our era (first year) to a given year inclusive. In fact, the Gregorian calendar was introduced much later, but here, for simplicity, we extend its effect throughout our era.
Method Format:
public static int leapYearCount(int year) { return year; }
Nothing comes to mind ... In principle, the task would be simple. But I need to solve it without using if
and for
. Only arithmetic and bit operations are allowed. Can someone tell me how to decide or direct the right path?