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.
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.
這道題中閏年不考慮大數(shù)情況,即3200年其實不是閏年隧饼,但在題目中看做閏年余指。
然后本想著400年一個大循環(huán)盛龄,里面有24*4+1=97個閏年,但是寫的代碼老是運行錯誤,就寫了個依次判斷閏年的循環(huán)窗宦,比較慢,但是通過了二鳄。即下面C代碼中的前部分:
#include "stdio.h"
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int a,b,b1;
int ans;
scanf("%d %d",&a,&b);
b1=b;
ans=a;
while(b > 0)
{
if ((ans % 4==0 && ans % 100=0) ||ans % 400==0)
b--;
ans++;
}
printf("%d\n",ans-1);
b=b1;
ans=a+(b/97)*400;
b=b % 97;
if(b==0)
printf("%d\n",ans-4);
else
{
while(b > 0)
{
if ((ans%4==0 && ans % 100=0) ||ans % 400==0)
b--;
ans++;
}
printf("%d\n",ans-1);
}
}
}