TopcoderArchiveVisit Topcoder
SRM23 Nov 2004
SRM 220

LeapAge

Problem statement, definition, constraints, and public examples.

Problem Statement

Your friend was born on "leap day" and has always been troubled by the fact that he just turned 24 this year on his 5th birthday. You would like to write him a nice program for his birthday to help him and other leap-day-born people keep track of how many birthdays they've had so far.

You will be given two years as ints, year represents the current year and born represents the year the person was born. You are to return the number of leap days that have occurred in that time span, not including the first year if it is a leap year, but including the current year if it's a leap year.

A leap year is any year that is a multiple of 4, unless it is divisible by 100 and not 400. For example, 1984 was a leap year, but 1900 wasn't, because it was divisible by 100 and not 400. 2000 was a leap year, because it was divisible by both 100 and 400.

Definition

Class:
LeapAge
Method:
getAge
Parameters:
int, int
Returns:
int
Method signature:
int getAge(int year, int born)
(be sure your method is public)

Notes

  • It is possible that year and born are not actually leap years.

Constraints

  • year and born will both be between 1582 and 10000 (1582 is when the Gregorian Calendar started, so there were no leap years before then).
  • year will be greater than born.

Examples

  1. 2004
    1980
    Returns: 6
    This is the case in the first paragraph of the problem statement.
  2. 10000
    1582
    Returns: 2042
    This is about as old as you get in this problem. Note that while the Gregorian Calendar (and therefore, leap years) started in 1582, 1582 wasn't a leap year.
  3. 2007
    1981
    Returns: 6
    You really don't know why your lying friend asked you to write this...
  4. 1981
    1980
    Returns: 0
  5. 1984
    1983
    Returns: 1
  6. 9700
    5795
    Returns: 947
Back to all problems