Problem Description
Ignatius was born in a leap year, so he want to know when he could hold his birthday party. Can you tell him?
Given a positive integers Y which indicate the start year, and a positive integer N, your task is to tell the Nth leap year from year Y.
Note: if year Y is a leap year, then the 1st leap year is year Y.
Given a positive integers Y which indicate the start year, and a positive integer N, your task is to tell the Nth leap year from year Y.
Note: if year Y is a leap year, then the 1st leap year is year Y.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains two positive integers Y and N(1<=N<=10000).
Output
For each test case, you should output the Nth leap year from year Y.
Sample Input
3
2005 25
1855 12
2004 10000
Sample Output
2108
1904
43236
Hint
We call year Y a leap year only if (Y%4==0 && Y%100!=0) or Y%400==0.题意:先输入一个整数,表示测试的数据的组数,每一组包括两个整数,分别表示起始年份、起始年份后第几个闰年。
分析:判断出第一个闰年之后不用再将年份逐渐加1,逐渐加4简单一些。
AC源代码(C语言):
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,n,i,j; 5 scanf("%d",&n); 6 while(n--) 7 { 8 i=j=0; 9 scanf("%d%d",&a,&b); 10 do 11 { 12 if((a%4==0&&a%100!=0)||a%400==0) 13 { 14 i++; 15 a+=4; 16 } 17 else a++; 18 19 } while(i!=b); 20 printf("%d\n",a-4); 21 } 22 return 0; 23 }
2013-01-24