PROBLEM 38
Easy

Leap Year

Programming Basics · C++

</>
STATUS Not solved

TASK

Problem

#38

Given a year, print `YES` if it is a leap year in the Gregorian calendar; otherwise print `NO`.

EXAMPLE

Example

Input
1900
Output
NO

LIMITS

Constraints

All integer magnitudes are at most 10^9; divisors are non-zero where used.
📖
LEARN Theory for this problem
+

`if`, comparison operators, and logical operators let a program choose output according to a condition.

Connection to “Leap Year”: here, intermediate values are best kept in named variables so the formula stays readable and data types remain clear.

💡
NEED HELP? Hints
+

['Write the condition directly and print exactly the required value.', 'After solving “Leap Year”, verify the algorithm on your own small example and on an allowed boundary case. Print only the required result with no extra text.']

ANSWER Solution
+
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main() {
    long long y;
    cin >> y;
    cout << ((y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) ? "YES" : "NO") << '\n';
    return 0;
}