Description
给出一个年份y,输出从y年开始(包括y)第n个闰年
Input
第一行为用例组数T,每组用例占一行包括两个整数y和n
Output
对于每组用例,输出从第y年开始第n个闰年
Sample Input
3
2005 25
1855 12
2004 10000
Sample Output
2108
1904
43236
Solution
水题~
Code
#include<cstdio>
#include<iostream>
using namespace std;
bool isleap(int x)
{
return x%4==0&&x%100!=0||x%400==0;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int y,n;
scanf("%d%d",&y,&n);
int res=0;
while(1)
{
if(isleap(y))//y也是闰年
res++;
if(res==n)
{
printf("%d\n",y);
break;
}
y+=(4-y%4);//优化
}
}
return 0;
}