思路:从第一个闰年开始,年份一直加4的算,算到第n个闰年。输出年份即可。
代码:
#include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <map> #include <set> #include <vector> #include <algorithm> using namespace std; #define mst(a,b) memset(a,b,sizeof(a)) #define eps 10e-8 const int MAX_ = 10010; const int MAX = 0x7fffffff; int T, n, y, cnt; bool isleap(int year){ return ((year%4==0&&year%100!=0)||(year%400==0)); } int main(){ scanf("%d",&T); while(T--){ scanf("%d%d",&y,&n); while(!isleap(y)){ y++; } cnt = 1; while(cnt != n){ y+=4; if(isleap(y))cnt++; } cout<<y<<endl; } return 0; }