PHP: Leap years

The calendar rule for leap years combines three conditions.

What to build

A program that tells whether a year is a leap year.

Requirements

  • Read a year.
  • Print leap if the year is divisible by 4 and not by 100, or if it is divisible by 400. Otherwise print not leap.

Input

One integer: the year.

Output

One line.

Constraints

1 ≤ year ≤ 9999.

Example

Input:

2000

Output:

leap

Why it works

The logical operators && and || combine the three divisibility checks in the order the rule is stated.

Examples

Example 1 · Input
2000
Expected output
leap
Example 2 · Input
1900
Expected output
not leap

Hints

Hint 1

A year divisible by 400 is a leap year.

Hint 2

Otherwise it is a leap year when it is divisible by 4 but not by 100.

Solution

Show one correct solution (try it yourself first)
<?php
$year = (int) trim(fgets(STDIN));
$leap = ($year % 4 === 0 && $year % 100 !== 0) || $year % 400 === 0;
echo $leap ? "leap" : "not leap", "\n";

▶ Open this solution in the compiler

Lesson: Operators and conditions →