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 |
#include <iostream>
using namespace std;
int main()
{
int a,start,n;
cin>>a;
while (a>0)
{
cin>>start>>n;
if ((start+1)%4==0)
start=start-3;
else if ((start+2)%4==0)
start=start-2;
else if ((start+3)%4==0)
start=start-1;
else if (start%100!=0||start%400==0)
--n;
while (n>0)
{
start=start+4;
if ((start%4==0&&start%100!=0)||start%400==0)
--n;
}
cout<<start<<endl;
--a;
}
return 0;
}