#T771. 过生日

过生日

Description

Xiao Ming was born in a leap year, and he wants to know when he can celebrate his birthday. Can you tell him?
Given a positive integer Y, representing the starting year, and a positive integer N, your task is to determine the Nth leap year starting from year Y.
Note: If Y itself is a leap year, then the first leap year is Y.

Input Format

The first line of input contains an integer T, representing the number of test cases.
Each test case consists of two positive integers Y and N (1 ≤ N ≤ 10000).

Output Format

For each test case, output the Nth leap year starting from year Y.

Example Input

3
2000 3
2001 2
2002 1

Example Output

2008
2004
2002

Explanation

  1. For the first test case (2000, 3), the leap years starting from 2000 are 2000, 2004, 2008, etc. The 3rd leap year is 2008.
  2. For the second test case (2001, 2), the leap years starting from 2001 are 2004, 2008, etc. The 2nd leap year is 2008.
  3. For the third test case (2002, 1), the leap years starting from 2002 are 2004, 2008, etc. The 1st leap year is 2004.

Constraints

  • 1 ≤ T ≤ 100
  • 1 ≤ Y ≤ 10000
  • 1 ≤ N ≤ 10000

Hint

A leap year is divisible by 4, but not by 100 unless it is also divisible by 400.

Solution Code

def is_leap(year):
    if year % 4 != 0:
        return False
    elif year % 100 != 0:
        return True
    else:
        return year % 400 == 0

T = int(input())
for _ in range(T):
    Y, N = map(int, input().split())
    count = 0
    current_year = Y
    while count < N:
        if is_leap(current_year):
            count += 1
            if count == N:
                break
        current_year += 1
    print(current_year)
3
2005 25
1855 12
2004 10000
2108
1904
43236

译文

CodesOnline