Statistics

Problem Statement for "LeapAge"

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

  7. 5305

    2537

    Returns: 671

  8. 8514

    7812

    Returns: 170

  9. 6228

    6134

    Returns: 23

  10. 8116

    3196

    Returns: 1193

  11. 2273

    2020

    Returns: 61

  12. 2684

    2118

    Returns: 138

  13. 4146

    2983

    Returns: 282

  14. 7717

    3156

    Returns: 1106

  15. 8166

    3439

    Returns: 1147

  16. 9106

    5309

    Returns: 920

  17. 5178

    2825

    Returns: 570

  18. 2788

    1935

    Returns: 208

  19. 9066

    8313

    Returns: 183

  20. 2113

    1626

    Returns: 118

  21. 3524

    3067

    Returns: 111

  22. 3431

    2556

    Returns: 211

  23. 7105

    5185

    Returns: 465

  24. 4642

    3967

    Returns: 164

  25. 3806

    3567

    Returns: 58

  26. 5498

    3304

    Returns: 532

  27. 5043

    4907

    Returns: 33

  28. 4242

    1863

    Returns: 577

  29. 4021

    3321

    Returns: 170

  30. 6001

    3237

    Returns: 670

  31. 7966

    5352

    Returns: 633

  32. 7891

    2320

    Returns: 1351

  33. 3984

    3953

    Returns: 8

  34. 9198

    1712

    Returns: 1815

  35. 2544

    2182

    Returns: 88

  36. 9321

    7087

    Returns: 542

  37. 4963

    1676

    Returns: 796

  38. 4310

    2477

    Returns: 443

  39. 2663

    1749

    Returns: 221

  40. 6569

    5936

    Returns: 154

  41. 1979

    1905

    Returns: 18

  42. 7373

    5620

    Returns: 425

  43. 8230

    6619

    Returns: 391

  44. 7595

    3024

    Returns: 1108

  45. 6037

    2415

    Returns: 879

  46. 2004

    1980

    Returns: 6

  47. 2004

    1900

    Returns: 26

  48. 2400

    1590

    Returns: 197

  49. 2004

    1983

    Returns: 6

  50. 9700

    5795

    Returns: 947

  51. 1981

    1980

    Returns: 0

  52. 2001

    1996

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: