Optimized leap year calculation